LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

save null character to excel

Solved!
Go to solution

Because MS Excel cells expect null terminated strings, I'm losing data when writing to Excel using active X from LabVIEW. What I am doing is typecasting an array to a string, and storing that string in a single Excel cell. But, if that string has a null character, all data after it is lost. Has anyone overcome this, and if so, how? The reason I want to do this is because my Excel spreadsheet is formatted in the following way

 

run1, set1, graph1 array, graph 2 array...graph10array

run 1, set 2, graph1 array, graph 2 array...graph10array

...

run2, set 1, graph1 array, graph 2 array...graph10array

....

run n, set n,graph1 array, graph 2 array...graph10array 

 

This allows me to search for "run n, set n" and get all the corresponding graph data very easily. Also, unfortunately, using a database is not exactly an option :(.

0 Kudos
Message 1 of 5
(2,417 Views)

Here's some ideas

 

Option1: Don't use excel use tdms instead, combine run and set into the group names, and put the graph arrays into channels, this should be much faster, and easier to deal with

 

Option2: Is there a reason a self contained database wouldn't work. Like the SQLite API for LabVIEW

 

Option3: Reencode your strings so they don't contain \0, then unencode them when you read them.

 

Option4: Change your format (each sample from the graphs goes into it's on cell)

0 Kudos
Message 2 of 5
(2,409 Views)
Matt,
Thanks for your response. The first two are customer driven. Their old format was in a DB and they want to keep that format, but move to excel so they can access other data visually from within Excel. If I was to put the graph stuff in a separate file, i'd then have to map to other files, check to make sure the files are there, etc.
Encoding and reencoding strings crossed my mind. However, this could potentionally cause "unencoding" of something I don't want to be unencoded. For example, let's say I replace all null characters with a, but then there is an a in the typecasted string which I don't want replaced. It will be replaced anyways. Is there a way around this? I'm thinking maybe do something like replace a null character with the ascii characters NULL. Then use a regex to search and replace. 
The last one would work and I may just map the data to columns on a different sheet and write all the points.

@matt W wrote:

Here's some ideas

 

Option1: Don't use excel use tdms instead, combine run and set into the group names, and put the graph arrays into channels, this should be much faster, and easier to deal with 

 

Option2: Is there a reason a self contained database wouldn't work. Like the SQLite API for LabVIEW

 

Option3: Reencode your strings so they don't contain \0, then unencode them when you read them.

 

Option4: Change your format (each sample from the graphs goes into it's on cell)


 

0 Kudos
Message 3 of 5
(2,404 Views)

@for(imstuck) wrote:

Encoding and reencoding strings crossed my mind. However, this could potentionally cause "unencoding" of something I don't want to be unencoded. For example, let's say I replace all null characters with a, but then there is an a in the typecasted string which I don't want replaced. It will be replaced anyways. Is there a way around this? I'm thinking maybe do something like replace a null character with the ascii characters NULL. Then use a regex to search and replace. 


Encoding/Decoding is a bit more sophisticated than simply replacing characters since you point out an obvious failure.  I'd suggest the Escape/Unescape HTTP URL.vi.  These use a standardized method and should do the job you require.

Message 4 of 5
(2,395 Views)
Solution
Accepted by GregFreeman

Could you just add an excel exporter, and handle the data internally in your own way.

 

I thought I had added a link for the encoding bit

http://en.wikipedia.org/wiki/Binary-to-text_encoding

Hex or Base64 encodings should be fine (although large).

 

Off the top of my head (so maybe broken) a possible encoding.

Replace all instances of '=' with '=0' then all instances of '\0' with '=1', then just reverse the replacements in either order to unencode, other bad characters can be replaced with a different '=(a different single letter that is not '=')'

Message 5 of 5
(2,391 Views)