我有一个C#WPF应用程序,它使用Excel互操作库来生成和打开Excel表。这对于使用Office 2003的XP计算机来说工作得很好。但是我最近将它迁移到运行Excel 2007的Windows 2007计算机上。现在我的excel出口不再适用了。它抛出类似如下的错误:在2007年打开excel时出错
System.Runtime.InteropServices.COMException (0x800A03EC): The document is corrupt and cannot be opened. To try and repair it, use the Open and Repair command in the Open dialog box and select Extract Data when prompted.
at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)
我用下面的代码打开我的excel文件..
private void OpenSavedData(string fileName)
{
var excelApp = new Application();
excelApp.Workbooks.Open(
fileName,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
excelApp.Visible = true;
Marshal.ReleaseComObject(excelApp);
}
这有没有问题Office 2003和XP的工作,但由于某种原因失败在Win7 & Office 2007.请你能让我知道任何可能的解决方法/解决方案吗?
感谢, -Mike
您可以传递一个参数(在'Open'中)告诉它是Office 2003文档吗? – Marco 2011-04-28 08:51:22