From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read a particular column in excel spreadsheet.

Hey everyone,

I'm trying to copy one csv file to a template. The problem is that im using a read from spreadsheet and copying the content using string. Which is fine. However, certain column just have numbers which is transfered as a text. It isnt too much of a problem but may interfere with some equations i have that will be converting those numbers in the same sheet. Is their a way to read the first column as a string and the other as a double? I believe i can index the array but im a little confused about it.

0 Kudos
Message 1 of 11
(4,918 Views)

Continue to read in the data as a 2D array of strings but then pick out the column (or columns) that have the numeric data and convert the string data to numeric data.

 

Clipboard01.jpg

0 Kudos
Message 2 of 11
(4,906 Views)
Yes, a simple Index Array is all that you need. Assuming you get a 2D string array of the entire file, wire to the column input of the function and then convert one column to numeric.

This is extremely basic. Please take some of the free tutorials. If you get stuck, you should attach your code and the file you are trying to read.
0 Kudos
Message 3 of 11
(4,904 Views)
WNM,

Why use a for loop when you can convert an array with a single function?
0 Kudos
Message 4 of 11
(4,898 Views)

You mean like this?

 

Clipboard02.jpg

 

 

Frankly because I did not know that those conversion funtions would work on arrays as well as individual values. 

But now that I do know, I'm not sure I'd use it anyway because the FOR-loop method gives you a level of error checking and reporting for the string-to-numeric translation that the single conversion function does not offer. You can feed the single function any manner of garbage and the only hint of a problem is that some or all of the resulting DBL array will be zero. The FOR-loop method will report a conversion error for the same garbage.

0 Kudos
Message 5 of 11
(4,884 Views)

Thanks Dennis and WNM. I looked at some examples but it didnt help me that much. @WNM i Came up with something similar using the examples within LV. When you use the numeric control, what number do you use? Lets say i want to copy column 2 and 3. would i set it at 2 and then 3?

0 Kudos
Message 6 of 11
(4,868 Views)
Arrays in LabVIEW are zero based. The first column is index 0, second column is index 1, etc. You use a single Index Array function and just drag it down to get multiple column selections.
0 Kudos
Message 7 of 11
(4,854 Views)
You can also use Array Subset to get multiple columns at once.
0 Kudos
Message 8 of 11
(4,846 Views)

Thanks for clearing that up, didnt know it was 0 based. Thanks you guys for the help.

0 Kudos
Message 9 of 11
(4,827 Views)

The attached example VI is one I put together long ago to help me sort out which array index was associated with which nested auto-indexing loop and which terminal input on the expandable array functions. SInce you are new to this, perhaps you might find it useful as well.

0 Kudos
Message 10 of 11
(4,792 Views)