【问题标题】:Open from template .xlt file as .xltx or xlsx从模板 .xlt 文件打开为 .xltx 或 xlsx
【发布时间】:2013-06-26 16:56:30
【问题描述】:

我有模板 .xlt excel 文件并尝试在 .xltx 或 xlsx excel 文件中显示数据。

ExcelApp = new Microsoft.Office.Interop.Excel.Application();

我尝试打开带有 xlt 扩展名的文件为 xltx

ExcelWorkBook = ExcelApp.Workbooks.Open(fileName,…)

当我打开名为 fileName 的文件时,我得到了错误

HRESULT 0x800A03EC 异常

在这一行

Range r = (Range) ExcelWorkBook.Columns["I", 0];

【问题讨论】:

标签: c# excel


【解决方案1】:

此问题可能由 CultureInfo 引起。 或者可能存在一些旧格式无效类型库


一个解决此错误的想法,您可以在执行与 Excel 相关的代码时将 CurrentCulture 设置为 en-US,并使用这 2 个函数重置回您的原始版本。

//declare a variable to hold the CurrentCulture
System.Globalization.CultureInfo oldCI;

//get the old CurrenCulture and set the new, en-US
void SetNewCurrentCulture()
{
  oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
  System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
}

//reset Current Culture back to the originale
void ResetCurrentCulture()
{
  System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多