LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read and write from excel to excel

Solved!
Go to solution

Hello, I'm not a labview programmer, but as part of a study, I need to create a small program that opens an excel file, will pick the width and height values (columns F and G) according to my part number (column B) and write them to another file. I tried to manage alone with the read or writte spreadsheet tools, but I can't. Does anyone have an example?

 

 

0 Kudos
Message 1 of 5
(2,967 Views)

Hi PluG,

 

read that CSV file using ReadSpreadsheetFile/ReadDelimitedFile into a 2D array of strings.

Then filter that 2D array based on the values in the 2nd column (column B in Excel).

Then save the remaining rows to a new CSV file using WriteToSpreadsheetFile/WriteDelimitedFile…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(2,946 Views)
Solution
Accepted by topic author PluG_33

My guess, without seeing your code, is that you're not using the correct delimeter. That csv file is NOT a csv file. It is semicolon delimited, so you have to specify the semicolon as the delimiter. 

Message 3 of 5
(2,941 Views)

Thank you !

 

0 Kudos
Message 4 of 5
(2,932 Views)

Expanding, slightly, on @jontrich1971, the extension ".csv" means "Comma-separated values", which, in turn, means a text file where a "delimiter" (such as a "comma") separates columns of (string) data, which can be numbers, booleans, character strings, etc. and lines of text define rows of data.  Microsoft Office has "high-jacked" this extension and given it an Icon that suggests it is an "Excel" file -- Excel knows how to read this type of Text file (but often needs to be told what character is being used as the delimiter, which seems to be a semi-colon in your case), but any routine that can read (and write) text files, even NotePad, can process this sort of file.

 

LabVIEW has a pair of functions, Read Delimited Spreadsheet and Write Delimited Spreadsheet.  In LabVIEW, the "default" delimiter of these files (which, again, use the default extension of ".csv") is not a comma, but a <tab> character.  If you read the Help on these two functions, you'll see that the Default Separator can be changed to any character you wish, but you need to wire it.

 

Once you have the right delimiter wired, you can use Read Delimited Spreadsheet to create a 2-D array.  Note you need to specify the format of the data as String (which accepts anything), Double, or Integer.  The default Format is Dbl.  I didn't know what would happen if you tried to read your file, which contains Strings, using the default Format -- I must say I was surprised by the result!  [I looked for the answer by quickly reading the Help -- I didn't find it, but may have overlooked it].

 

Now that you have a 2D array and know the rows and columns you want, you should be able to write the LabVIEW code to manipulate these data yourself (or ask colleagues, or the Forum, for help).  To write out the updated results, you need to decide if you want to "recreate" the old file (filling in the data you didn't process, and taking the "mixed format" of the file into account) or a new file consisting of just the changed data rows and columns.  You follow the same ideas and choice of options for Write Delimited Spreadsheet as you did for Read Delimited Spreadsheet.

 

Bob Schor

0 Kudos
Message 5 of 5
(2,928 Views)