LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing a string into excel sheet

Hello, 

 I am trying to create a NI.

Problem: The current CSV Writer VI I have is functional, but it only accepts one line at a time. If I want to write to it 10+ times, which I expect to, I have to put it in a loop and it inefficiently opens and closes the CSV file I’m writing to 10 times instead of opening it once and writing to it 10 times.

 

What I want: I would like to make a new VI which would accept multiple lines and write more efficiently

0 Kudos
Message 1 of 4
(733 Views)
  1. Open the file using the Open/Create/Replace File vi
  2. Pass the file reference to your acquisition loop
  3. Write a line of comma separated values plus an End of Line Constant using Write to Text File
  4. Loop until done
  5. Close the file using Close File vi

oseCapture.PNG

========================
=== Engineer Ambiguously ===
========================
Message 2 of 4
(700 Views)

@Jaz24 wrote:

 

What I want: I would like to make a new VI which would accept multiple lines and write more efficiently


As RTS shows, you only need to move the Open and Close file functions outside the VI and any writer loop.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 4
(665 Views)

You failed to post even a picture (shudder) of your code, so I can't tell if you are mis-using the (very useful) "Write Delimited Spreadsheet VI" or not.

 

Write Delimited Spreadsheet is designed to let you write "intermittently" arrays of data (either 1D or 2D) to a file.  If you are designing a program that writes "occasionally" (which can mean once a day, once a minute, or even once a second), and especially if you run your program for, say, an hour or more, you might not want to do a File Open, write, write, write, write, ... write, File Close as a glitch somewhere between File Open and File Close could leave your "un-closed" file in a precarious state, and risk the loss of all the data.

 

Write Delimited Spreadsheet, as you noted, does an Open, go to end-of-file, write, Close.  Of these, the Open and Close are the "slow" steps, so if you need to write rapidly, doing Open, lots of writes, Close is much more efficient.

 

But did you notice that the Write Delimited Spreadsheet accepts 2D Data?  So if you have an Array of Lines (I think you mentioned 10 lines), and you wired the 10-line Array to the function, it would Open, go to end-of-file, Write 10 lines, Close, probably about 10 times faster than doing one line at a time, yet preserving the "safety from an Error Crash" of your data.

 

Bob Schor

0 Kudos
Message 4 of 4
(645 Views)