LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview beginner trying to convert Txt to Xlsx

Hi,

I've posted earlier today about my problem struggling to figure a way convert a txt file to a xlsx. so  some of you convinced me to give ActiveX a try, here Iam, i found a bunch of VI on Internet and here Iam, I feel that Im getting closer to what Im looking for but still dont work. 
Atached to my message you'll find the VI and the text file Im trying to convert. If any of you can spot the problem and help me. Id reaally appreciat it !! 

Thanks

Download All
0 Kudos
Message 1 of 18
(4,728 Views)
  • Your Text file has an unusual format.  The first line seems different from the remaining, in that the first entry is much longer (it has a prefix of "2.06211341", and then it and all the other lines say _Tete_Alu.  Is this what you intend to save?).
  • Your text file appears to have 1 column of String information, 13 columns of numeric, specifically I32, information, and a final column of String information that can (possibly) be interpreted as encoding a date.
  • How are you planning to write your data?  As a single 2D Array (in which case it better be all Strings)?  As a "row-at-a-time" (in which case it needs to be String-13 numerics-String)?  As a Column/block at a time (in which case it needs to be "1D String Column, 2D Numeric Block, 1D String Column)?
  • Your VI doesn't appear to do anything (and fails to do it, at that!).  It seems to Open a file, Save it, Close it (but "Close" is false?), and exit.

In your previous post, you suggested you could use ActiveX (based on a proprietary technology that even Microsoft, who originated it, has abandoned) and the RGT.  I provided links to doing what you need using the RGT.  Before discovering this useful Toolkit, I also tried, and gave up on, ActiveX.  "Your Mileage May Vary".

 

Bob Schor

0 Kudos
Message 2 of 18
(4,725 Views)

Hi Bob, thanks for. taking the time and trying to help. 

- Well, to answer your first questions, I'm going to attach to my response the excel workbook Im expecting from the labview program to create for me. 

 

- About me VI, what I did is at a first glance, I didnt had the Save and Close modules, So all what the program was doing is opening my txt file in an excel workbook which was great because it's what I was looking for, but It didnt save it..

Im only a Labview beginner, So Im just trying whatever people say to me that I should give a hit. Im giving ActiveX now a chance cause I didnt found much on RGT. hope I can figure out a way because Im getting sick of it, It has been 3 days that Im trying different ways for this.. 

THanks

0 Kudos
Message 3 of 18
(4,717 Views)

@haamza09 wrote:

Im giving ActiveX now a chance cause I didnt found much on RGT.


Did you find what I thought was an excellent "Revised" RGT code here in the LabVIEW Forums?  I thought I was pretty clear on how to find it, but here is another way:

  • Open the Forums.
  • In the Search bar, type <Quote>Revised<space>, where <Quote> = " and <space> is a space.  Open the example, which is now 5 years old, and has a "deprecated" function that LabVIEW tells you how to fix.  I think it should answer most of your questions, but you'll have to read it, and examine it, and maybe even run it.

Incidentally, there have been reports on the Forum about problems with the RGT (and, for all I know, ActiveX) and Excel 2016.  I'm using Excel 2013, and this code works fine.  I believe the solution to the Excel 2016 issues is also in the LabVIEW Forums, but I don't have a reference to it.

 

Bob Schor

0 Kudos
Message 4 of 18
(4,707 Views)

Usually, I use the right click > Export to Excel Method

which is suitable, as long as you don't have to batch-process more than 5 Excel files.

 

The following is from:

Moving Data From LabVIEW Into Excel

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

 

 

There are many different ways to move data from NI LabVIEW software into Microsoft Excel. Each method has advantages and drawbacks, so we’ll explore some of the available options to help you find the right one for your application.

Comparison Table

 

Export

TDMS File

CSV File

Report Gen.

DIY ActiveX

NI DIAdem

Interactive

 

 

 

 

Programmatic

1

Custom formatting

 

 

 

Works without Excel being installed

 

 

 

Automatically saves metadata

 

 

 

 

Requires additional software

 

2

 

3

 

4

File based transfer

 

 

 

Automation interface transfer

 

 

1 data can be sent to Excel programmatically but requires manual action to save the file
2 requires the TDM Excel Add-In for Microsoft Excel – free to download and installs with recent versions of LabVIEW
3 requires the NI LabVIEW Report Generation Toolkit for Microsoft Office 
4 requires DIAdem

 

0 Kudos
Message 5 of 18
(4,703 Views)

I already seen it, but I dont really understand. It doesnt seem to be what Im looking for. All what I want is a tool that does open a txt file and save it as Excel. Your program seems to be so complex for me and for sure not what Im looking for. Thank you for your help though

0 Kudos
Message 6 of 18
(4,695 Views)

DIY ActiveX/.NET

The Report Generation Toolkit is built on top of the Excel ActiveX interface. You can use this API either through direct ActiveX calls or the Microsoft.Office.Interop.Excel .NET assembly to automatically create Excel files. The code snippet below produces essentially the same result as the Report Generation Toolkit example but instead uses a .NET interop assembly to communicate with Excel. As you can see, the code ends up a little more complex but anyone with a background in ActiveX/.NET programming should feel right at home.


[+] Enlarge Image

 

Here is the output of the above code snippet:

 0# you need MS Excel 2007 or higher installed on your PC

1# get that demo to work**

2# modify the demo to your needs

 

If this is to complex for you (as you have said several times),

than maybe you should ask yourself, if this is the right task for a beginner.

 

 

 

** I had to manually re-select Microsoft.Office.Interop.Excel(15.0.0.0)>ApplicationClass()

see attached

0 Kudos
Message 7 of 18
(4,682 Views)

I always save my data in a Tab delimited text file. Excel has no problem opening and importing text files natively. See my response to your original post. 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 8 of 18
(4,658 Views)

this snippet will create a .xlsx file named "Test file.xlsx"  from a 2d String array** in the same place where the .vi is located

I use a 2d string array constant, which may be replaced with "Read delimited Spreadsheet.vi", to read a real .txt file

 

save-txt-to-xlsx.png

 

 

which version of LabView are you using?

 

0 Kudos
Message 9 of 18
(4,651 Views)

You want to use the Workbooks.OpenText method. 

aputman
0 Kudos
Message 10 of 18
(4,640 Views)