LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Converting .XLSX to .CSV in LabVIEW

Hello everyone.

I am searching for a solution in LabVIEW to convert every sheet from a excel file in .csv files. I use .csv files with Read from Spreadsheet to extract some data and and it will be more efficient to give the path to excel file in the application than to save each sheet with .csv format and give the path to each of them.

 

Has anyone any idea if I can implement what I propose?

0 Kudos
Message 1 of 8
(5,930 Views)

Hi Voda,

 

use functions from RGT (ReportGenerationToolkit) to read the worksheets…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(5,903 Views)

I'm a little bit confused on what you want to do.  But first, let me digress a minute:

 

  • A CSV file is a "Comma-separated Values" file, a plain text file that uses a delimiter (often a comma, hence the name, but other characters, such as a <tab>, the LabVIEW default, are also commonly used, particularly when the data "being separated" contains commas (like numeric string representations in Europe).
  • A CSV file has nothing to do with Microsoft Excel.  However, Microsoft decided to associate an "Excel-like" icon with this file type.  Excel can "recognize" this Text file, can open it, and can allow you to use Excel to examine and modify the data.  However, any "Excel-specific" changes you make (like formatting) won't be saved when you close the file unless to save it as a .XLS or .XLSX file.

So here's my question:  what do you really want to do?  Do you have an Excel (.xlsx) file?  Does it have any Excel-specific "features" (such as formatting, column widths, coloring, graphs, etc.)?  What do you really want to do with it?

 

You mention that the Excel file has multiple Sheets, and that you want to process all (?) or some (?) of them (this is not clear).  You seem to be hung up on how to handle the multiple Sheets, and seem to be looking for a generalization of the CSV format that would allow you to have a single File with multiple CSV-formatted data inside it.  This is sounding already too complicated.

 

So here are some suggestions.  Let's assume your Excel file is called My Data.xlsx, and it has four sheets, Run 1, Run 2, Run 3, and Run 4.  Note that I'm assuming you have the Report Generation Toolkit, which allows you to read and write Excel (.xlsx) files.

  1. Create a folder called My Data.  Open My Data.xlsx.  In a While Loop, open each Sheet and read the data.  Use Write to Delimited Spreadsheet to create a CSV file named for the WorkSheet (i.e. the first file will be in \My Data\Run 1.csv).
  2. Instead of fussing with CSV files, just use the Excel File.  Use the RGT to open My Data.xlsx.  In a While Loop, open each Sheet, read the data, extract what you need, make whatever changes to the file you might want (you didn't mention doing this, but you certainly could, if it was useful), and if it makes sense to do so, save the extracted data using some naming convention so you know from which Sheet the data came.  Much simpler, but it may not be what you really want to do ...

Bob Schor

 

P.S. -- did you realize that the RGT can be used to read Excel files, as well as write them?

Message 3 of 8
(5,836 Views)

So, you do as Bob suggested, or you read the xlsx as a zip file, and open *.xlsx\xl\worksheets\sheet1.xml and extract the table from the <row>, <c> and <v>-tags.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 8
(5,816 Views)

@Bob_Schor wrote:

So here's my question:  what do you really want to do?  Do you have an Excel (.xlsx) file?  Does it have any Excel-specific "features" (such as formatting, column widths, coloring, graphs, etc.)?  What do you really want to do with it?


As stated in the thread title and the first post, they want to open that .xlsx file, take the values, and put them into a csv file.

0 Kudos
Message 5 of 8
(5,795 Views)

@natasftw wrote:

As stated in the thread title and the first post, they want to open that .xlsx file, take the values, and put them into a csv file.

Yes, but they specifically said they didn't want to have to deal with multiple CSV files, hence my confusion and request for clarification.  I was trying to figure out what they wanted to do, as I could (mis-)interpret the post in multiple ways.  I've been wrong before (as recently as yesterday!).

Bob Schor

0 Kudos
Message 6 of 8
(5,791 Views)

@Yamaeda wrote:

So, you do as Bob suggested, or you read the xlsx as a zip file, and open *.xlsx\xl\worksheets\sheet1.xml and extract the table from the <row>, <c> and <v>-tags.

/Y


in this thread, someone attached a .llb based on Active X to read cell values from an .xlsx file

Message 7 of 8
(5,762 Views)

@alexderjuengere wrote:


in this thread, someone attached a .llb based on Active X to read cell values from an .xlsx file


today, I rather would suggest to use this: https://forums.ni.com/t5/LabVIEW/Darren-s-Occasional-Nugget-09-26-2022/m-p/4257690#M1239480

0 Kudos
Message 8 of 8
(2,704 Views)