LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write String to Spreadsheet

Hello,

 

I have two Booleans and an alphanumeric string that I want to write to a spreadsheet.  The attached code changes the two Booleans to strings, builds an array comprised of the two Booleans and the alphanumeric string and writes the data in a spreadsheet.  After that, it tells the VI what state to go to next where a similar process is repeated.  I am using a VI called Write_String_to_Spreadsheet_File.VI that I downloaded from this Website to write to the spreadsheet.  There is only one problem.  The Write_String_to_Spreadsheet_File.VI appends data to the end of the file.  I need to be able to replace specific data if values change without changing previously entered values.  Is there anyway that I could modify my code to specify the exact row in the spreadsheet to write to?

 

Thanks,

 

Drew

 

 

 
 
0 Kudos
Message 1 of 6
(3,469 Views)
You will first have to read in the existing file with a Read From Spreadsheet file which will return a 2D array. You can then replace a specific element in the array with Replace Array Subset. After that, use the Write to Spreadsheet to replace the old file.
0 Kudos
Message 2 of 6
(3,465 Views)
Can you provide a quick bit of example code?
0 Kudos
Message 3 of 6
(3,460 Views)
Here is with the standard Read From and Write To Spreadsheet File functions. Since you are using strings, you will have to modify Read From Spreadsheet to read and return a 2D string array. Instructions for how to do this are on the diagram.
0 Kudos
Message 4 of 6
(3,448 Views)
Hello,
 
Here is the code I've generated.  It uses the FILE INFO.vi to determine whether or not the file exists. 
 
1) If the file does not exist, the WRITE_STRING_TO_SPREADSHEET_FILE.vi creates the file and writes the data entered in the first row of the spreadsheet. 
 
2) If the file exists, the Read_Text_from Spreadsheet_File.VI should read in the data from the spreadsheet file and the WRITE_TEXT_TO_SPREADSHEET_FILE.vi should write the new data in the first row of the spreadsheet.  This part isn't working, and I can't figure out why.
 
Can anyone propose a solution?
 
Thanks,
 
Drew
 
P.S.  I tried to solve my problem by using the Index Array.vi in case 2 to address each cell to be rewritten in case 2 (r0,c0, r0,c1, and r0,c2) individually, but it didn't work correctly either.  I think the problem there was the fact that the output of the Index Array.vi becomes 2 diminsional whereas the output of the Build Array.vi is one diminsional.
 
 
0 Kudos
Message 5 of 6
(3,431 Views)
One immediate problem I see is that in your no error case, you've got the write file set to append and not overwrite. And to help prevent another post, when you set it to overwrite, you will get an advisory dialog. To prevent this, open your write function and at the Open/Create/Replace function, wire a false to the advisory dialog input. And why are you using two different Write functions? One is called Write_Text and the other is called Write_Strings. They're both the same as far as I can tell.
0 Kudos
Message 6 of 6
(3,421 Views)