开发者

Excel Automation in VS2010

开发者 https://www.devze.com 2023-04-03 14:26 出处:网络
I know that there are millions of posts about this already but I cant seem to find one that mirrors my issue.

I know that there are millions of posts about this already but I cant seem to find one that mirrors my issue.

I am using VS2010 and want to automate excel and I'm trying to work through the example here.

MS Tutorial

The problem is when I go to add the reference as mentioned

3.Add a reference to the Microsoft Excel Object Library. To do this, follow these steps: •On the Project menu, click Add Reference. •On the COM tab, locate Microsoft Excel Object Library, and click Select.

There is no such reference available.

Could someone please let me know if this is the right way to automate excel with VS2010.

If it is could someone please let me know why I dont开发者_C百科 have the COM option for excel.

Im wanting to write in VB.net but if someone has an example in C# that would be fine.

Kind Regards

Ash

I have tried implementing automation using the Microsoft.Office.Interop.Excel.Application dll but i get the following exception when I try to create the excel application.

This line generates the error.

EXL = New Microsoft.Office.Interop.Excel.Application()

This is the exception

Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))


If you have Office 2010 installed on your machine but still don't see it in the COM tab then there are reasonable odds that you have the 64-bit version of Office installed. Visual Studio is a 32-bit program, it cannot see the registry entries for 64-bit COM servers.

Workarounds are to use the primary interop assembly, it ought to be installed on your machine. Use the .NET tab and select Microsoft.Office.Interop.Excel. Next option is to import the type library directly. Use the Browse tab and navigate to c:\program files\microsoft office\office14 and select excel.exe. Set the Copy Local property of the added references to True to avoid having to deploy the PIA to the target machine.

Also be sure that your app can run as a 64-bit process. In vb.net that's selected with Project + Properties, Compile tab, scroll down, Advanced Compile Options, set Target CPU to "AnyCPU".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号