12-01-2017 10:34 AM
I am trying to read a range of cells from Excel and convert it to a LabVIEW array of Strings.
Unfortuantely, '.NET Object to Variant.vi' cannot handle 2D Arrays, even though you can convert 2D Arrays with 'To .NET Object.vi'. My workaround for this at the moment is to reference each cell in my range and use nested For Loops to recreate the array as a LabVIEW data type.
Has anybody found a solution better than this?
Ps. Using LabVIEW 2014
12-04-2017 02:33 AM
>Unfortuantely, '.NET Object to Variant.vi' cannot handle 2D Arrays
Seems to work just fine to me. Do you get an error? Broken wire? Something you don't expect?
The result is a variant, you might expect a 2D array. The variant is a 2D array, but you need to use "Variant To Data" to convert it to a 2D array.
07-02-2025 06:47 AM - edited 07-02-2025 06:53 AM
I am having an issue here with 2D arrays as well. Here is what I am doing.
This method used to work for active X:
What am I messing up here?
I do not get anything out of the Value2. I am getting an error 1172 which seems to be the go to for anything you are having issues with in .net. I'm not getting an error out of the Value2 property. I am getting the 1172 out of the .net to variant. Here is the error I am getting:
Error 1172:
Invoke Node in .NET Object to Variant.vi->Open Excel Workbook using .net.vi
<APPEND>
Method Name: <b>.NET:Convert Object To LabVIEW Variant</b>
07-02-2025 07:19 AM
First step would be to wire that Variant to an indicator on the front panel. And then enable "Show Type" in the popup-menu. This will show you what the Variant knows about the internal data type it contains. From there you might have to do a specific conversion to make it work.
07-02-2025 07:29 AM - edited 07-02-2025 07:31 AM
It shows up as void. So I have to be doing something wrong before this. I am calculating a range (A1:AO414) and that seems to be working correctly. Can you give me another clue? I don't seem to be getting anything from the get range function. Is there a different or better way to get the worksheet ref? I am guessing that is where my problem lies.
07-02-2025 08:04 AM
Do you need to use .NET? Here's a good tool - GitHub - dnattinger/read-xlsx-file: A VI that will read the contents of an .xlsx file into LabVIEW w...
07-02-2025 08:09 AM - edited 07-02-2025 08:13 AM
Yes I would like to do this in .net. I do not want alternates. I have a whole module that I wrote 15-20 years ago to use with Excel. It is more capable and easier to use than the report generation toollkit. I want to port it to something that is going to be supported moving forward. I keep hearing that Active X is going away. I am just trying to get ahead of the game. Plus it is a fun project to work on. If I can figure out how to get the data out I should be most of the way there. It just isn't working they way I expect and there is nothing anywhere that tells you why. It sound like a few people on here have figured it out. I am just hoping someone will point me in the right direction.
07-02-2025 08:23 AM
I can ask for a single cell and I get the correct response. When I ask for a range I get nothing.
07-02-2025 09:13 AM
@aeastet wrote:
[...] easier to use than the report generation toollkit. [...] I keep hearing that Active X is going away.
The one I linked doesn't use the RGT or ActiveX. If that changes anything.
07-02-2025 09:17 AM - edited 07-02-2025 09:18 AM
@aeastet wrote:
I can ask for a single cell and I get the correct response. When I ask for a range I get nothing.
Not sure if this helps or not, but maybe you're using an invalid range. AI tells me that Excel Interop uses 1-based indexing, so you should start the range from Cells[1, 1]
instead of Cells[0, 0]
. Just an idea...