LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

replace a single value in a spreadsheet

Is there a way to write a value in the same cell of the same spreasheet in labview?

I just want to be able to replace the same cell in the spreasheet.

Can someone please help me?

0 Kudos
Message 1 of 8
(3,558 Views)

What is a "spreadsheet"?

 

Are you talking about excel? A LabVIEW table? A 2D array? A file?

 

Please attach some simplified code so we get a better idea what you need. Thanks!

0 Kudos
Message 2 of 8
(3,550 Views)

I am trying to use a write to spreadsheet vi, to replace a single cell in the tab delimitted spreadsheet.

0 Kudos
Message 3 of 8
(3,521 Views)

You can't.  Write to Spreadsheet File creates a text file.

 

What you would need to do is use Read From Spreadsheet File to read in the entire text file where it becomes a 2-D array.  Use Replace Array Subset to replace whichever cell you want.  Then use Write to Spreadsheet File to write the tab delimited text file back out again.

0 Kudos
Message 4 of 8
(3,514 Views)

You cannot edit values in a delimited spreadsheet files, because the field width is typically not fixed. Thus it is not possible to calculate file offset for the element location and if the new element string is longer or shorter, all later values would need to be shifted.

 

Solution: You need to read the entire spreadsheed, replace the value and write the changed array back.

 

Alternatively, if this is a numeric array, use a flat binary file instead. Now any field can be edited by writing to the correct file offset.

0 Kudos
Message 5 of 8
(3,511 Views)

I use the .NET  Automation Reference to connect to Excel in many projects.

If you have the Report toolkit, you can dive into the "behind-the-scenes" of the Excel reports to see how they do things.

 

Also, check out this link which shows many options for getting data into Excel.

Near the bottom of the page are the .NET gory details for the adventurous do-it-yourselfer.

http://www.ni.com/newsletter/51339/en/

 

I have multiple subVIs to perform individual actions, like

Open the Excel application,

Open a Workbook,

Select a Worksheet,

Select a Range,

Read / Write data to / from a Range...etc..

 

I've created a simple demo that shows the basic steps to take.

see attachment

 

 

 

0 Kudos
Message 6 of 8
(3,495 Views)

@jeffneuner wrote:

I use the .NET  Automation Reference to connect to Excel in many projects.

 


He has a plain tab delimited text file. Nothing to do with excel.

0 Kudos
Message 7 of 8
(3,492 Views)

Well, technically, what you need to do is (a) read the entire file and organize it so you can "reach" a specified cell, (b) modify the cell, and (c) write the entire file back out.  

 

One (the easier, sensible) way to do this is to use LabVIEW's Delimited Spreadsheet functions for steps (a) and (c), resulting in an Array handled in (b).  Another (sillier, but workable) method is to (a) read the .csv file with Excel, which organizes it into an Excel Worksheet, (b) tell Excel to modify a particular Cell, then (c) write the entire Excel file back out in .csv form.

 

Given a sensible, easy way to do something, why not do it another, harder, more obscure way?  Your customers will think you are so clever and you can earn the Big Bucks.

 

Bob "the Cynic" Schor 

0 Kudos
Message 8 of 8
(3,464 Views)