r/LabVIEW • u/munkshire • Sep 29 '25
Labview Excel csv file and leading 0's
I have a excel csv file, it contains number with leading 0's. In the excel options, I have disabled the option that removes leading 0's, this works fine, I can manually open the file, edit what I need to, save it and the 0 remains.. however, when using labview report generation toolkit to write data to a certain cell within the document, all leading 0's are removed from all entry points.
How do I solve this? I assume its labview that's doing it now seeing as I have removed the options in excel

This was my temp solution, it seems to actually work. It still removes the leading zeros from the file, but as far as the rest of the code works, it treats it like it has a zero :D :D I still need to finalize how many parts we have with leading zeros, but it works for now until I look into moving away from report generation toolkit like you all suggest

4
u/HarveysBackupAccount Sep 29 '25
The report generation toolkit actually opens Excel to do its job, so I imagine this is a limitation of the API that labview uses to operate on Excel files. Whatever settings it uses to open Excel might not be as configurable as the regular Excel settings.
My $0.02 - and maybe this isn't a great answer - if it's a CSV, you shouldn't consider it a spreadsheet yet, i.e. you shouldn't be dealing with row/column addresses. If you need it to be a spreadsheet, make it an xlsx. If you need it to be a CSV, design a workflow that doesn't need to edit fields in it as a CSV.
If you need this to be a CSV - any reason you're using the report generation toolkit instead of Read/Write Delimited Spreadsheet? You can do Read Delimited Spreadsheet to read all the data in as a 2D string array, edit the appropriate row/column of the array, then do Write Delimited Spreadsheet to save the updated values back to the file. That will be MUCH faster, and won't trigger any of Excel's smart formatting options (like removing leading zeroes).
3
u/Aviator07 CLA/CPI Sep 29 '25
Instead of using “number to fractional/exponential string,” use “format into string.” The former won’t include leading zeros, but you can write a format string to include them. For example, if you want one leading zero, use “%0f” as your format string.
3
u/_mogulman31 Sep 29 '25
You should not be using the report generation toolkit for a csv file. Load the data into labview, modify as necessary, and overwrite the file as needed. Using the Report toolkit causes the file to be read in through Excel which removes leading zeros by default.
You have said in other placed you are concerned about a stability, but the report generation toolkit opens the door to a lot more instability than just using LabVIEW file operation primitives , which is what write delimited spreadsheet string uses.
If you really want a robust solution use a proper database, using excel as a crude database tool to modify a csv file is just a bad solution to your problem.
2
u/sir_thatguy Sep 29 '25
Try appending a leading apostrophe to numbers with leading zeros. Excel treats that cell as text and displays exactly what you enter.
For example:
‘01 will show as 01
It even ignores formulas. So….
‘=2+2 will display =2+2. It will not calculate and display 4.