LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

open txt file to excel in Lab view !

How can I do something close to the VB function 'Workbooks.OpenText' but in Labview !
To insert a txt file in excel, but from Labview, witout running a macro !

Thanks
0 Kudos
Message 1 of 11
(4,701 Views)
You have to do the same thing (use the same sequence of ActiveX calls (properties and methods) used in VB). It only looks different. So, use an ActiveX > Automation Refnum and after opening Excel (Automation Open), use the reference to CREATE "Workbooks" property and from this one to CREATE "OpenText" method. Also, don't forget to close the reference when you're done and consider to use "Visible" property to have the possibility to see what's happening when executing your VI.
If you want to see some examples (ActiveX related), take a look in your LV folder\examples\comm\ExcelExample.llb or search ni.com with "+activex +excel"

Good Luck
Message 2 of 11
(4,703 Views)
Thanxs...
I will try...
0 Kudos
Message 3 of 11
(4,701 Views)

Hi!

I tried to use the opentext method but I just don't get it. If I look at various excel examples for Labview they always use the fact that the Workbooks.Open method gives a reference to a workbook where in the next step the sheet is created from. But obviously Workbooks.Open can't just be replaced by Workbooks.OpenText because it doesn't give me a reference. So I don't get to the point where I can write to a sheet.

Does anyone have an example of how to do this (I use LV 8.2 an XL2k)? Would be very helpful ...

Thanks,
BT

0 Kudos
Message 4 of 11
(4,379 Views)
Everything you need is in the Excel Examples library. After opening a reference to the application, use the VI Open Specific Workbook.vi to get a reference to the workbook. Pass this reference to the VI Open Specific Worksheet.vi. This gives you a reference that you can use to manipulate your data.

Mike...

PS: The thread you added on to is 5 years old. It would be advantagous to start a new thread in the future as it will improve your chances of getting a response.

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 5 of 11
(4,366 Views)
Hi Mike,
 
thanks for your reply. My problem lies exactly in using the VI Open Specific Workbook.vi . Because in the VI the file is opened as a normal Excel workbook. But when I change the open method to the opentext method the VI doesn't work any longer because there seems to be no reference on a workbook by the opentext method. Unfortunately the file I'd like to write data to is not really an Excel file but just a text file. That's why I would like to use the opentext method instead.
But up to now I didn't find an example how to do this.
 
BT
0 Kudos
Message 6 of 11
(4,350 Views)
If you have a text file, there is no reason at all to use the Excel ActiveX properties and methods. Just use any of the file read functions in LabVIEW. Read From Spreadsheet File is just one of your options.
0 Kudos
Message 7 of 11
(4,342 Views)
OK, I see. As Dennis said if the file is text there is no reason to go to the added complication of ActiveX calls. LV has a variety of options for working with text files. What is the structure of the file? If it is tab-delimited data like you can read into Excel your best choice is something like the "spreadsheet" read and write VIs that come with LV, and which are available under the File I/O menu - though if this is part of a larger application you will probably want to create your own version that exposes the error clusters.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 8 of 11
(4,337 Views)
There seems to be at least one advantage in using ActiveX although it is a simple text file: you can address a specific row/cell. I think that's especially helpful when there is an existing file where you just want to replace some rows ...
To do the same with the spreadsheet VIs the only possibility I can think of is reading the existing file to an array, replace the data in the array and then write it back to the file.
 
Do you know a smarter way to do this?
 
BT
 
0 Kudos
Message 9 of 11
(4,305 Views)
It strikes me that if you are wanting to do this sort of updating you should be using something other than a text file to hold your data - perhaps an actual spreadsheet file or (more likely) a database. What is it that you plan to do with the text files and the data they contain?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 10 of 11
(4,295 Views)