Jump to content
styrum

Write table to Excel using .NET

Recommended Posts

Now that it looks like Microsoft deprecated ActveX Automation interface in Excel 2016, the only other interface left is .NET interop assemblies. I have tried to reproduce Excel - Write Table.vi using .NET instead of ActiveX. The result of the effort is attached. There is a big problem though: The Range.value2 property could take 'anything' without a problem when using ActiveX (it was taking any variant)! But now it wants a .NET object. And the 'To .NET Object.vi' doesn't accept a 2D array of variants! So, say getting a recordset from a database (which is returned as a 2d array of variants) and then writing it, as it is, to a new Excel workbook is no longer possible as far as I understand. This is really sad. A 2D Table of strings or doubles is still OK. So, if you need to use those, you can with the attached code

Write Table to Excel with DotNET.vi

Share this post


Link to post
Share on other sites

Strange, I have Excel 2016 and my Report Generation Toolkit code still works just fine, with its usual ActiveX implementation underneath.

Share this post


Link to post
Share on other sites

Did you try that 'Excel - write table.vi' example shipped with LabVIEW? Maybe there are some options during installation of Excel/Office or after it to install/turn on or not install/turn off ActiveX support?

Share this post


Link to post
Share on other sites

Any idea how to write a 2D array of variants as a whole into Excel sheet using .NET calls? Doing it one cell at a time is apparently not feasible for large recordsets.

Edited by styrum

Share this post


Link to post
Share on other sites

OK, so ActiveX still works in Excel 2016. But it is older than .NET and they can still deprecate it in the next version. So, experience on how to communicate with Excel via .NET can become very valuable.

Share this post


Link to post
Share on other sites

Sorry no, I have not tried the .NET interface.

I suspect MS will have lots of angry customers if they truly decide to remove (rather than just deprecate) the ActiveX interface. I am going to leave it to NI to solve that problem if it arises,

Share this post


Link to post
Share on other sites
On 10-6-2016 at 11:26 PM, styrum said:

OK, so ActiveX still works in Excel 2016. But it is older than .NET and they can still deprecate it in the next version. So, experience on how to communicate with Excel via .NET can become very valuable.

While ActiveX is already a legacy technology according to MS, they won't just chop it off like that from any of their products without a really strong reason. Depreciation will happen eventually, first by prominent remarks in the documentation, then by removing the documentation slowly from all Microsoft servers but removing it from the applications itself? No way! Windows still supports many technologies from its 16 bit protected mode times, such as DDE, just to name one and while MS says: Don't use it! it's still part of the shell interface to all normal Windows applications.

Edited by rolfk

Share this post


Link to post
Share on other sites
21 minutes ago, rolfk said:

Windows still supports many technologies from its 16 bit protected mode times, such as DDE, just to name one and while MS says: Don't use it! it's still part of the shell interface to all normal Windows applications.

Or as Linus Tovalds says: "Never break user space" and "if you change the ABI, I will crush you!" :D . (Shame they don't listen to him :frusty: )

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.