我有一個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