01-13-2009 01:03 PM
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
Solved! Go to Solution.
01-13-2009 01:10 PM - edited 01-13-2009 01:20 PM
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?
01-13-2009 01:35 PM - edited 01-13-2009 01:36 PM
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.
01-13-2009 02:16 PM
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
01-13-2009 02:27 PM - edited 01-13-2009 02:29 PM
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.
01-13-2009 02:53 PM
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
01-13-2009 03:07 PM
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) ?
01-13-2009 03:28 PM - edited 01-13-2009 03:30 PM
Here is a possible solution to the (potential) problem. Convert to a string array and erase the added data before writing to the file
01-13-2009 03:35 PM
01-13-2009 03:36 PM
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