Converting program generated pseudo .xls to UTF-8

Copper Contributor

I have a program that writes a file in the following format, and gives the file an .xls file extension.

 

"Header line 1 ..."

"Header line 2 ..."

""

Head1   <TAB>   Head2   <TAB>   Head3

Data1_1  <TAB>  Data1_2  <TAB>  Data1_3

Data2_1  <TAB>  Data2_2  <TAB>  Data2_3

Data3_1  <TAB>  Data3_2  <TAB>  Data3_3

(There is only a single tab character separating the Head# fields and also for the Data# fields,
I just put spaces around <TAB> to make it more readable.)

 

When the file is opened with Excel, it gives a warning message:

"The file format and extension of <file> don't match. ... Do you want to open it anyway?"

The user clicks yes, and the file opens in Excel.  The Text Import Wizard is not invoked.

 

The code was changed to contain Chinese in UTF-8.  The file would open, but the characters
were garbled because Excel didn't know it was UTF-8.  We added the 3-byte "byte order mark"
for UTF-8 as the first 3 characters of the file.  The Chinese characters are now displayed correctly.
But now, when the file is opened, the data fields in the table are concatenated together into the
first cell of each row, they aren't put into sequential cells in the row.
Data1_1Data1_2Data1_3
rather than one item per cell of the row.

If I change the filename to .xls, or if I change the tabs to commas, Excel will open the file,
but puts the user into the Text Import Wizard, where they have to specify if there are headers,
whether the data is fixed-width or delimited, what the delimiter is, etc.

I would like the users to be able to open the Chinese files the same as the English ones,
where they just click "Yes" and the file opens, and they don't have to go through the hassle
of the import wizard.

Do you have any suggestions for a small fix?

Thanks in advance!

0 Replies