I have developed an application which imports data into Microsoft Excel.
我开发了一个将数据导入Microsoft Excel的应用程序。
Am using VS2005 + .NET 2.0 and Microsoft Office 2007 is installed on my machine (Office 12).
我的机器(Office 12)上安装了VS2005 + .NET 2.0和Microsoft Office 2007。
The compiled application works fine if I run it in my machine, but when I deploy the application to other machines say those using lower versions (Office 2000), I am getting the error:
如果我在我的机器上运行它,编译的应用程序工作正常,但是当我将应用程序部署到其他机器时,如果使用较低版本(Office 2000),我收到错误:
Could Not Load File or Assembly Microsoft.Office.Interop.Excel, Version 12.0.0.0
无法加载文件或程序集Microsoft.Office.Interop.Excel,版本12.0.0.0
How would I then enable my application execute properly regardless of the Office (Excel) installed on the machine?
无论机器上安装的Office(Excel)如何,我如何才能正确执行应用程序?
Thanks.
Some Updates: I placed the two DLLs referenced, namely Microsoft.Office.Interop.Excel.dll (Version 12.0.0.0) and Office.dll (Version 12.0.0.0) in my bin folder. I have set the properties for this reference to Copy Local = True and when I compile my application, the DLLs are copied in the debug / release folder.
一些更新:我在我的bin文件夹中放置了引用的两个DLL,即Microsoft.Office.Interop.Excel.dll(版本12.0.0.0)和Office.dll(版本12.0.0.0)。我已将此引用的属性设置为Copy Local = True,当我编译应用程序时,DLL将被复制到debug / release文件夹中。
Now, when I try to run the application, I already got out of the error: "Could Not Load File or Assembly Microsoft.Office.Interop.Excel, Version 12.0.0.0"
现在,当我尝试运行应用程序时,我已经摆脱了错误:“无法加载文件或程序集Microsoft.Office.Interop.Excel,版本12.0.0.0”
but another error came up which is: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object TextVisualLayout, Object Local)
但是出现了另一个错误:System.AccessViolationException:尝试读取或写入受保护的内存。这通常表明其他内存已损坏。 at Microsoft.Office.Interop.Excel.WorkbookClass.SaveAs(Object Filename,Object FileFormat,Object Password,Object WriteResPassword,Object ReadOnlyRecommended,Object CreateBackup,XlSaveAsAccessMode AccessMode,Object ConflictResolution,Object AddToMru,Object TextCodepage,Object TextVisualLayout,Object Local)
So, how do I actually create an application which would be able to export the datatable data into Excel regardless of the version of Office installed?
那么,我如何实际创建一个能够将数据表数据导出到Excel中的应用程序,而不管安装的Office版本如何?
Thanks.
4 个解决方案
#1
2
Look at MS Office Wrapper for .NET - it's wrapper independent on version of Office ( testeod MS Office 97 - 2007 and works ).
看看MS Office Wrapper for .NET - 它是独立于Office版本的包装器(testeod MS Office 97 - 2007并且可以工作)。
#2
1
In the past I have found that if you make sure all the references for Office (i.e. not the System ones) are set to copy local it will work.
在过去,我发现如果您确定Office的所有引用(即不是系统引用)都设置为复制本地,它将起作用。
I generally compile with the Office 2003 PIAs (which you can get from Microsoft's website somewhere) and the output has worked with Office 07. I havent tried Office 2000 or XP in a long while so not sure if the output would work.
我通常用Office 2003 PIA编译(你可以从微软的网站上获得)并且输出与Office 07一起工作。我很长时间没有尝试过Office 2000或XP,因此不确定输出是否可行。
#3
0
This is because it's specifically looking for version 12 of that assembly.
这是因为它专门寻找该程序集的第12版。
In your csproj, find the reference to that assembly in your References folder. Go into Properties for that reference, and turn Specific Version to False.
在csproj中,在References文件夹中找到对该程序集的引用。进入该参考的Properties,并将Specific Version改为False。
#4
0
You will have fewer problems - but you still might have problems - if you build against Excel 2003 instead of Excel 2007.
如果您使用Excel 2003而不是Excel 2007构建,则问题会更少 - 但您仍可能遇到问题。
SpreadsheetGear for .NET is an Excel compatible library for .NET which you can deploy with your application without worrying whether your users have a particular version of Excel (it will work even if they do not have any version of Excel).
SpreadsheetGear for .NET是一个Excel兼容的.NET库,您可以使用您的应用程序进行部署,而无需担心您的用户是否具有特定版本的Excel(即使他们没有任何版本的Excel也能正常工作)。
You can see samples with C# and VB source code here and download a free trial here.
您可以在此处查看带有C#和VB源代码的示例,并在此处下载免费试用版。
Disclaimer: I own SpreadsheetGear LLC
免责声明:我拥有SpreadsheetGear LLC
#1
2
Look at MS Office Wrapper for .NET - it's wrapper independent on version of Office ( testeod MS Office 97 - 2007 and works ).
看看MS Office Wrapper for .NET - 它是独立于Office版本的包装器(testeod MS Office 97 - 2007并且可以工作)。
#2
1
In the past I have found that if you make sure all the references for Office (i.e. not the System ones) are set to copy local it will work.
在过去,我发现如果您确定Office的所有引用(即不是系统引用)都设置为复制本地,它将起作用。
I generally compile with the Office 2003 PIAs (which you can get from Microsoft's website somewhere) and the output has worked with Office 07. I havent tried Office 2000 or XP in a long while so not sure if the output would work.
我通常用Office 2003 PIA编译(你可以从微软的网站上获得)并且输出与Office 07一起工作。我很长时间没有尝试过Office 2000或XP,因此不确定输出是否可行。
#3
0
This is because it's specifically looking for version 12 of that assembly.
这是因为它专门寻找该程序集的第12版。
In your csproj, find the reference to that assembly in your References folder. Go into Properties for that reference, and turn Specific Version to False.
在csproj中,在References文件夹中找到对该程序集的引用。进入该参考的Properties,并将Specific Version改为False。
#4
0
You will have fewer problems - but you still might have problems - if you build against Excel 2003 instead of Excel 2007.
如果您使用Excel 2003而不是Excel 2007构建,则问题会更少 - 但您仍可能遇到问题。
SpreadsheetGear for .NET is an Excel compatible library for .NET which you can deploy with your application without worrying whether your users have a particular version of Excel (it will work even if they do not have any version of Excel).
SpreadsheetGear for .NET是一个Excel兼容的.NET库,您可以使用您的应用程序进行部署,而无需担心您的用户是否具有特定版本的Excel(即使他们没有任何版本的Excel也能正常工作)。
You can see samples with C# and VB source code here and download a free trial here.
您可以在此处查看带有C#和VB源代码的示例,并在此处下载免费试用版。
Disclaimer: I own SpreadsheetGear LLC
免责声明:我拥有SpreadsheetGear LLC