1

I have both 2003 and 2007 Excel versions installed on my machine. The current source code uses Office11 (2003) interop assembly Microsoft.Office.Interop.Excel.dll to create the Excel template.

When I create the template and open in Excel 2007, it opens perfectly. The same template when I open in 2003 I get the message "File format is not valid".

_excel = new Excel.Application();
_workbooks = _excel.Workbooks;
_excel.Visible = false;

_excel.DisplayAlerts = false;

// create and add a workbook with 1 worksheet named "Sheet1" 
_workbook = _workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);

_sheet = (Excel.Worksheet)_workbook.ActiveSheet;
4

1 回答 1

1

如果您安装了两个版本的互操作程序集,您可能有一个绑定重定向程序集,它将 Office11 调用重定向到 Office12 程序集。

这里

在全局程序集缓存中安装和注册 Office PIA(使用 Office 或通过安装 PIA 的可再发行包)时,绑定重定向程序集也仅安装​​在全局程序集缓存中。这些程序集有助于确保在运行时加载正确版本的主互操作程序集。例如,当引用 2007 Microsoft Office 主互操作程序集的解决方案在具有相同主互操作程序集的 Microsoft Office 2010 版本的计算机上运行时,绑定重定向程序集指示 .NET Framework 运行时加载 Microsoft Office 2010 版本的主要互操作程序集。有关详细信息,请参阅程序集绑定重定向。

这意味着您的代码正在调用 Excel 2007,因此创建了 Excel 2003 无法读取的 Excel 2007 格式文件(没有转换插件)。

于 2010-04-13T19:26:52.337 回答