简体   繁体   English

NET 3.0中不能与interop.Exel一起使用

[英]Can't work with interop.Exel in .NET 3.0

I've developped an application for my internship, I've done it in C# .NET 4.5 with Windows 8 64 bits, full compatible with .NET 4.0. 我已经为实习开发了一个应用程序,我已经在Windows 8 64位的C#.NET 4.5中完成了该程序,它与.NET 4.0完全兼容。

But in fact, I have to install it on old computers with WinXP 32/64 bits and .NET 3.0 without administrator rights... 但实际上,我必须在没有管理员权限的情况下将其安装在具有WinXP 32/64位和.NET 3.0的旧计算机上...

So now I'm trying to put my project in .NET 3.0 from .NET 4.0 and I have some problems with that, in my code I have: 所以现在我试图将我的项目从.NET 4.0放到.NET 3.0中,与此有关的还有一些问题,在我的代码中,我有:

using Excel = Microsoft.Office.Interop.Excel;

"Office" is underlined with blue. “办公室”用蓝色下划线。

I also have a error message with "Reference assembly is missing blablabla" So ok, I go to add references assemblies but... Impossible to add them, I tried all of them but it doesn't change anything... 我也收到一条错误消息“引用程序集丢失blablabla”,好吧,我去添加引用程序集,但是...无法添加它们,我尝试了所有它们,但它没有任何改变...

I'm searching on the web but I can't find a good and clear answer, so I'm there :) 我正在网上搜索,但找不到一个清晰明确的答案,所以我在这里:)

Thanks for all (and to all =P) 感谢所有人(并感谢所有人= P)

Solution: 解:

Downgrade your interop.Excel DLL and add it to your references assemblies. 降级您的interop.Excel DLL并将其添加到引用程序集中。

You'll have this error: Impossible to convert type 'object' to 'Microsoft.Office.Interop.Excel.Worksheet'. 您将遇到此错误:不可能将类型'object'转换为'Microsoft.Office.Interop.Excel.Worksheet'。 An explicit conversion exists (cast blablabla) 存在显式转换(广播blablabla)

xlWorkSheet = xlWorkBook.Sheets[1];

So just change this to this: 因此,只需将其更改为:

xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets[1];

您可能需要降级office interopt DLL的版本。

Do you have to read and write xls files? 您是否需要读写xls文件?

If you only want to read and write xlsx files, you can use OpenXML. 如果只想读写xlsx文件,则可以使用OpenXML。 It would be a full-managed solution for your problem. 这将是您的问题的完全托管的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM