LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building a table to save in Excel problem

Hi all, i have attached a simple example that recreates my problem. That is when i have set my header option to multiple line input and add text, Excel then identifies the carriage return as a EOL. Is there any way round this without having to manually create individual header strings and then concatanating?
0 Kudos
Message 1 of 7
(3,710 Views)
Hello,

I don't see the attachment, could you attach it please?

Regards,
Ryan K.
0 Kudos
Message 2 of 7
(3,705 Views)
0 Kudos
Message 3 of 7
(3,701 Views)
Unfortunately, this seems to be a limitation of Excel. The Excel Text Import Wizard won't let you specify a row delimiter for text import, recognizes both carriage returns and line feeds as row delimiters and doesn't (in my opinion) treat string identifiers (quotes) correctly by ignoring delimiters found between them. Unless someone else has an idea, I can only see three possible solutions.

1. Replace the carriage returns with spaces (or some other character, like a pipe), I've attached a modified version of your VI which does this. Using this method you could still keep the multi-line functionality in LabVIEW, but you would loose it in Excel.

2. Write an Excel Macro which does a custom import.

3. Use a more robust data analysis program (shameless plug: DIAdem allows you to specify a line delimiter in its text import wizard ;)).

Regards,
Ryan K.
Message 4 of 7
(3,692 Views)
One other note, even if you build the header strings manually and concatenate them, you still won't be able to get Excel to recognize a multi-line cell. You'll need to set it up in such a way that the two lines are in two different cells.
0 Kudos
Message 5 of 7
(3,691 Views)
Ryan, thanks for the advice. Whilst we are on the subject of Excel properties, is it possible to set the Column widths and Row heights?
0 Kudos
Message 6 of 7
(3,676 Views)
First of all, just a little explanation of what you are doing: The file you are saving, and then opening in Excel is known as a tab delimited text file, it contains only data and information on how to divide that data into rows an columns (each column is separated by a tab and each row is separated by a newline). This is a common format for storing spreadsheet style data, and doesn't have anything specific to do with Excel. You can open it in any program which recognizes ASCII files, and that program will determine how to interpret the tab-delimited data (the way that Excel interprets it is the cause of your previous problem). This file format contains no other information (i.e. formatting). So the answer to your question is "no" the way you are currently doing things.

However, there are a couple of other paths you could take:

1. In contrast to a tab-delimited text file, a .xls file is an excel-specific binary file which contains data, in addition to formatting and other informatin (i.e. divides the data into workbooks and sheet, specifies column heights and widths, adds charts and graphs, etc.). Obviously, creating a .xls file requires an awful lot more work than the tab delimited text file (especially since it uses a pseudo-proprietary binary format). For practical purposes, you would never manually create a .xls file.

What you can do is call the actual excel program through ActiveX and use it to write a .xls file. This isn't a trivial task, however there is lots of code already written. The development library has tons of examples of using Excel through ActiveX, and the Report Generation Toolkit is specifically designed to create reports in more advanced formats, including Excel .xls files, by using ActiveX (boy, I'm just full of shameless plugs this week ;)).

2. Another option would be to stick with a tab-delimited text file, but include the formatting information, such as the column width, in a separate cell. You could then write an Excel macro which adjusts the formatting based upon the values of these cells. While you are at it, you could also manually specify how the file is imported to solve your previous problem. The disadvantages of this approach are first, you have to write an excel macro, which isn't something I can help you with (I usually stick to DIAdem script), but you can probably find lots of good examples on the web. Second, anyone opening your file is going to have to have that Excel macro, and will have to know to run it rather than opening the file normally (i.e. you wouldn't just be able to double click on the file in Windows Explorer, you'd need to open up Excel and run a macro).

Hope that helps,
Ryan K.
Message 7 of 7
(3,665 Views)