LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing To An Existing Spreadsheet

Highlighted
I am collecting data with my program and writing to a spreadsheet after each
loop. My problem is that I have created a spreadsheet and I want labview
to open that existing spreadsheet and write to it. I seem to have no problem
if it is a new spreadsheet, but no luck writing to an existing spreadsheet.

Any Help Is Greatly Appreciated,

Thanks

Aaron
0 Kudos
Message 1 of 3
(1,132 Views)
Hi!

If you just want to save new data to existing old data,
use "append to file" in the "write to spreadsheet.vi"

But if you want to add new columns in the existing spreadsheet?

See the message wrote by Craig Graham.

In that message,

"1st: The ideal is to build the whole table within your for loop, using
shift
registers to hold the header string and data array, and concatenate the new
header text and columns as they become available. Then when the for loop
finishes, write the entire header and table to a file in two single
operations.

2nd: If this cannot be done- for instance if the program takes a long time
to
execute and you're concerned with the long term reliability of the system-
then each time new data is available, you'll have to first rename your
datafile to "datafile.bak", after deleting any currently existing
"datafile.bak". You then have to load in the previous datafile, concatenate
the new columns and then write it back out to disk. This sequence of
operations could be contained within a "append columns to spreadsheet
file.vi" function. There is no way to add columns to a spreadsheet file,
since the file is just lines of text.

3rd: A more efficient but slightly more complex method, since you know in
advance
how many rows and columns are needed, would be to treat the file as a
"virtual array" and first initialise it with zero data, taking the same
number of characters as the real data- for instance the first two columns
would be

time nnnV
n.nn n.nnn
n.nn n.nnn
n.nn n.nnn
"

I used 1st method, and then I did add new column to spreadsheet.

If iteration number of loop is small, you can use build array in my thought.

I want to say "thank a lot " to Craig Graham again.

Jin-ho Nam..



"Aaron" wrote in message news:3a80827b@newsgroups.ni.com...
>
> I am collecting data with my program and writing to a spreadsheet after
each
> loop. My problem is that I have created a spreadsheet and I want labview
> to open that existing spreadsheet and write to it. I seem to have no
problem
> if it is a new spreadsheet, but no luck writing to an existing
spreadsheet.
>
> Any Help Is Greatly Appreciated,
>
> Thanks
>
> Aaron
0 Kudos
Message 2 of 3
(1,132 Views)
njh wrote in message
news:3a80c845@newsgroups.ni.com...
> Hi!
>
> If you just want to save new data to existing old data,
> use "append to file" in the "write to spreadsheet.vi"
>
> But if you want to add new columns in the existing spreadsheet?
>
> See the message wrote by Craig Graham.

Public acknowledgement is always nice to see 🙂

In your case, as I recall, you needed to add columns, which is tricky. In
this case I suspect the poster has a spreadsheet-type ASCII file on disk and
just wants to append new rows to it, which is a more standard operation.
Most of the file operation VIs, including "Write to Spreadsheet File",
default to overwriting the original file with the new one, but have a
Boolean input "Append to File?" which if s
et true will add the new data as
new rows at the end. Since extra lines of text are just being added at the
end, rather than a new number inserted on the end of each line, it's not
necessary to load back the file on disk, add the data and save it back out.

If I've understood wrong and by "spreadsheet" is meant actually an Excel
spreadsheet, then of course that's different and slightly more involved. 🙂
0 Kudos
Message 3 of 3
(1,132 Views)