2011-04-28 3 views
0

Excel interop 라이브러리를 사용하여 Excel 시트를 생성하고 열 수있는 C# WPF 응용 프로그램이 있습니다. 이것은 Office 2003이 설치된 XP 시스템에서 잘 작동합니다.하지만 최근 Excel 2007이 실행되는 Windows 2007 시스템으로 마이그레이션했습니다. 이제는 더 우수한 수출품이 더 이상 효과가 없습니다. 그것은 다음과 같은 오류가 발생합니다 : 내가 아래에있는 내 엑셀 파일을 열도록 코드를 사용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) 

을 ..

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에서 작업 아무런 문제가 없습니다 만, 몇 가지 이유로 실패 on Win7 & Office 2007.이 문제를 해결할 수있는 방법이나 해결책을 알려주십시오.

감사합니다, - 마이크

+0

Office 2003 문서라는 매개 변수 ('Open')를 전달할 수 있습니까? – Marco

답변

1

Windows 7로 업그레이드 할 때 동일한 문제가 발생했습니다. 64 비트 환경에서 실행되는 WPF 코드에 갑자기 충격을 받았을 것입니다. 확실하지 않아!

내 솔루션이 약간 과감했습니다. I 은 항상 .Net 앱에 불안정한 수준을 추가 한 VSTO 라이브러리를 사용하는 대신 OpenXML 라이브러리를 사용하여 내 WPF 앱의 "Excel로 내보내기"코드를 완전히 다시 작성했습니다.

나는 내가했던 모든 소스 코드, 플러스 데모, 여기에 제공되는 것을 문서화했습니다 당신이 내 라이브러리에 http://www.mikesknowledgebase.com/pages/CSharp/ExportToExcel.htm

를 연결하면 데이터 집합을 내보내거나 DataTable을가 간단하다 한 줄의 코드 추가.

CreateExcelFile.CreateExcelDocument(myDataSet, "C:\\MikesExcelFile.xlsx"); 

매우 간단하지 않습니다.

희망이 도움이됩니다.

마이크

4

은 당신이 엑셀 2003과 함께 초기 바인딩을 사용하고있을 수 있습니다 생각하고 엑셀 2007 작업을 나던 이유는 기본적으로 당신이 적절한 상호 운용성을 참조하면서 응용 프로그램을 다시 컴파일되어 무엇을해야하는지 Excel 2007 용 라이브러리 (Microsoft.Interop.Office.Excel 버전 1.6)는 Office 2007이 설치된 컴퓨터에서 "참조 추가"-> "COM"에서 찾을 수 있습니다. Google은 초기 및 후기 바인딩을 통해 더 많은 정보를 얻을 수 있습니다. http://peltiertech.com/Excel/EarlyLateBinding.html

관련 문제