LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to Spreadsheet adding extra rows in csv file

Solved!
Go to solution

Hi All,

 

I am creating a program which measure current over time.  It is working well, but when I write to spreadsheet, there are extra rows between the row of data.

 

I created a header file, which is passed into the while loop where data is entered into an array and then entered into the spreadsheet.  If I simply display the array, there are no extra rows, but when I open the csv file in excel, there are more rows.  I am pretty new to labview, but everything is running the way I want (it is a simple program) except for this.

 

 

0 Kudos
Message 1 of 13
(6,840 Views)

Why are you overwritting the entire each time you capture data?  Set the "Append To File" to TRUE and write the header before the loop.  Then you just have to write your single line inside of the loop.

 

Even better would be to open/create a file, write the header, and then directly write your data to the text file, and close the file after the loop.  This will make your loop run a little faster since the file stays open instead of opening, writing, and closing each time you add more data.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 13
(6,829 Views)

The reason I am saving each time is because I want the data to save if I have to click stop.

 

I will try your suggestion soon to make the loop run faster, thank you.

 

However, I still don't understand why it is adding extra lines in the csv file, but at the same time, it isn't if I am simply displaying the array.

0 Kudos
Message 3 of 13
(6,825 Views)
Solution
Accepted by topic author _natalie_

There is a carriage return or line feed in your string data.  You can get rid of this by adding a "trim whitespace" function between the "visa read" function and the "replace array subset" function.

Message 4 of 13
(6,812 Views)
Solution
Accepted by topic author _natalie_

@_natalie_ wrote:

Hi All,

 

I am creating a program which measure current over time.  It is working well, but when I write to spreadsheet, there are extra rows between the row of data.

 

I created a header file, which is passed into the while loop where data is entered into an array and then entered into the spreadsheet.  If I simply display the array, there are no extra rows, but when I open the csv file in excel, there are more rows.  I am pretty new to labview, but everything is running the way I want (it is a simple program) except for this.

 

 


You should alter your File I/O like crossrulz said to at least append to file instead of saving the entire array of file data each time around. If this ran for a really long time, that array will get bigger and bigger and bigger until you bog down your program. Since you're looping at about 0.2Hz according to your defaul value, opening the file and closing it each time isn't a problem, but you should keep that in mind for future programs or if you want to speed this one up.

 

Excel is looking for line feeds and carriage return values to know when to go to the next line. It looks like you're reading from a VISA resource. Your instrument might be using a carriage return or line feed as its end-of-data marker, so that could be what's causing your problem if you're including that. Try adding a Trim Whitespace node to that string right after your VISA Read and see if that fixes your problem.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 5 of 13
(6,805 Views)

Thank you Jordan, works perfecty!

 

Is it giving a linefeed because it is outputting a string? 

0 Kudos
Message 6 of 13
(6,798 Views)

Thank you as well James_Morris.  I will try appending the file to make it run faster, still learning!

0 Kudos
Message 7 of 13
(6,791 Views)

_natalie_ wrote:

Is it giving a linefeed because it is outputting a string? 


No.  It is because your instrument is sending the Line Feed.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 13
(6,787 Views)

Thank you, too, crossrulz!

0 Kudos
Message 9 of 13
(6,783 Views)

A good rule of thumb when working with VISA or other instruments that are communicating with strings is to add an indicator in there that shows you the output and configure the indicator to be "\" display (right-click menu option). This will show you all of the whitespace characters in "\" format. Line feeds are "\n", return key is "\r", space is "\s". Those whitespace characters have caused me a lot of grief in the past.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 10 of 13
(6,739 Views)