LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read from a text file that is longer than 65536 lines and write the data to an Excel spreadsheet and have the data write to a new column once the 65536 cells are filled in a column?

Solved!
Go to solution

I have data that is in basic generic text file format that needs to be converted into Excel spreadsheet format.  The data is much longer than 65536 lines, and in my code I haven't been able to figure out how to carry over the data into the next column.  Currently the conversion is done manually and generates an Excel file that has a total of 30-40 full columns of data.  Any suggestions would be greatly appreciated.

 

Thanks,

Darrick 

0 Kudos
Message 1 of 11
(4,148 Views)

Just to understand your question a little more clearly, is this what you want to do:

You have a 1D array that is 1 by >65536.

You would like to convet that array to a 2D array, by only allowing each column to grow to about 1600 rows long?

So it will be a 2D array that is 40 x 1600
Is that correct?

Message Edited by Cory K on 01-13-2009 01:20 PM
Cory K
0 Kudos
Message 2 of 11
(4,145 Views)

If the above scenario is correct, this is one solution.

You could initialize a 2D array outside of while loop A.

Put while loop B inside while loop A.

In loop B, add values to an array until the array gets 1600 values long (or whatever number you want).

Then exit B, and append that array to a 2D array, this will make a new column.

 

 

You will need some more logic to get the data, because in my example, the data comes from a numeric control.

If your data right now is in a really long 1D array (in LabVIEW) it should be easy enough. Just read in a subset of data,

then in the next iteration, read the next subset of data, beginning where the last one left off.

Message Edited by Cory K on 01-13-2009 01:36 PM
Cory K
Message 3 of 11
(4,134 Views)

Thanks for the response.  Yes, I have a 1D array >65536.  But I need the data to fill an entire column before writing to a new column.  In Excel,  once Column A has a full 65536 lines of data then the "would be cell #65537" starts Column B cell #1 and so on until the end of the file.  I will try the example posted and update accordingly.

 

Thanks,

Darrick 

0 Kudos
Message 4 of 11
(4,117 Views)

No need to use nested For loops. No need for any loop anyway. You just have to use a reshape array function. The picture below shows how to proceed.

 

However, there may be an issue if your element number is not a multiple of the number of columns : zero value elements will be added at the end of the last column in the generated 2D array. Now the issue depends on the way you intend store the data in the Excel spreadsheet : you could convert the data as strings, replace the last zero values with empty strings, and write the whole 2D array to a file (with the .xls extension ;)) using the write to spreadsheet function. Only one (minimal) problem : define the number of decimal digits to be used;

or you could write the numeric array directly to a true Excel spreadsheet, using either the NI report generation tools or ActiveX commands, then replace the last elements with empty strings.

We need more input from you to decide how to solve these last questions. 

Message Edité par chilly charly le 01-13-2009 09:29 PM
Chilly Charly    (aka CC)
Message 5 of 11
(4,112 Views)

Thanks for the quick response.  My goal was to write the data directly into Excel using the "write to spreadsheet.vi".  That vi allows for formatting the number of decimal digits which I think would solve the problem you're referring to, correct?  

 

Thanks,

Darrick 

0 Kudos
Message 6 of 11
(4,103 Views)

DarrickZ a écrit: [...] That vi allows for formatting the number of decimal digits which I think would solve the problem you're referring to, correct?  

Correct... but how are you planning to manage the added zero data at the end of the array ? Or are your columns perfectly filled (integer multiple of 65536) ? 
Chilly Charly    (aka CC)
0 Kudos
Message 7 of 11
(4,099 Views)
Solution
Accepted by topic author DarrickZ

Here is a possible solution to the (potential) problem. Convert to a string array and erase the added data before writing to the file

 

Message Edité par chilly charly le 01-13-2009 10:30 PM
Chilly Charly    (aka CC)
Message 8 of 11
(4,095 Views)
Wow, CC's idea beats the heck outta mine.
I'd go with that one.
Cory K
0 Kudos
Message 9 of 11
(4,090 Views)

Ideally, all all columns would be filled perfectly except for the very last column.  This is the current method used when done manually.  

 

Thanks,

Darrick 

0 Kudos
Message 10 of 11
(4,089 Views)