LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview beginner trying to convert Txt to Xlsx


@aputman wrote:

You want to use the Workbooks.OpenText method. 


To elaborate....wire a True constant into the Tab field and you're done.  The fieldInfo field can be used to specify the format of the imported data.  This is how it would be done in VB

    Workbooks.OpenText Filename:="C:\Users\aputman\Desktop\Text file.txt", _
        Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
        Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 2), _
        Array(2, 2), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
        Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
        , 3)), TrailingMinusNumbers:=False

And in Labview....

2018-07-25_11-42-36.png

The first column in the array corresponds to the imported column number in Excel.  The second column corresponds to the field type (1 = General, 2 = Text, 3 thru 8 = Date formats, 9 = Do Not Import).

aputman
Message 11 of 18
(1,772 Views)

@alexderjuengere

Thanks for your responde, I'll give it a try right now ! Im using LV2014

0 Kudos
Message 12 of 18
(1,755 Views)

@ haamza09:

attached as 2014

 

---------

 

@ aputman: this looks really straight forward, if task is "convert .txt to .xlsx"

I've rebuild this snippet from your screenshot, finally none of the active X nodes throws an error anymore.

aput_ACTIVEx.png

 

so, this is supposed to open the .txt file directly in Excel -

now we need to figure out how to close EXCEL and save the imported .txt as .xlsx to disk.

Could you guide us which activeX properties or methods to use?

 

 

 

 

 

 

 

 

0 Kudos
Message 13 of 18
(1,742 Views)

@alexderjuengere wrote:

 

 

 

 

so, this is supposed to open the .txt file directly in Excel -

now we need to figure out how to close EXCEL and save the imported .txt as .xlsx to disk.

Could you guide us which activeX properties or methods to use?


The OpenText method opens the file and adds it to the workbooks collection.  You'll need to index the workbooks collection to grab this particular workbook and call the Save method.  The save method asks for a Filename and FileFormat.  XLSX fileformat is the number 51.  

 

2018-07-26_8-42-59.png

aputman
Message 14 of 18
(1,732 Views)

@aputman: thank you!

the "Excel Get ActiveX References VI " requires the Report Generation Toolkit, which became a part of the Professional Development System, so I'm fine with this.

 

It's a convenient way to automatically to create the ActiveX "Excel._Application" reference, which I have done manually

 

 

0 Kudos
Message 15 of 18
(1,716 Views)

Hi haamza09,

 

I'd like to offer help exploring an alternative path to the one you've requested.  If your end goal is to explore your data, analyze it and make reports out of it, then perhaps you'd be better served with NI's DIAdem product instead of Excel.  You may be operating under company requirements you can't influence such that you don't have that flexibility, but I thought I'd float the idea.  What I'd be happy to do is build you a quick DataPlugin that would make your *.txt files a native file format for DIAdem, such that you could drag data files into DIAdem interactively to load them.  From there graphing would also be simple drag&drop and analysis would be dialog-based interactive selections.

 

As an aside, have you tried changing the file extension of your *.txt file to *.xls?  You have to click "yes" in the initial pop-up dialog, but otherwise double-clicking your ASCII file named with an *.xls extension loads the file into Excel exactly as you indicated you wanted.

 

Let me know if you're interested in exploring DIAdem,

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 16 of 18
(1,689 Views)

Hi @aputman & @alexderjuengere
Thanks for your help !! 
The solution you @aputman suggested to me seems to be the one I was looking for !! Hence, I'm running on Labview 2014, so I cant drag the png to the diagramme, can you please send me the VI pleaase ?? 

0 Kudos
Message 17 of 18
(1,663 Views)

Haamza,

 

I intentionally did not post the image with the code embedded.  Nor did I save it to disk, which means you'll need to recreate it on your own. It's not difficult to recreate and you may learn something in the process.  Smiley Wink

aputman
0 Kudos
Message 18 of 18
(1,653 Views)