WagnerJu
(Fresh Scripter)
2009-03-20 02:56 PM
DOS to ANSI

Hi folks,
I have a complicated question....

I use some shell-output which gives me characters in german umlaut (äüöß)
I redirect this output to a file which I read line per line in my kix-script.
After some string operations I output these lines on the console.
The console output is redirected to a file because I need to add some more shell output to this file.
The resulting file is a csv-file which I want to import in Excel for further formatting.

What happens is this:
The shell outputs a string which contains umlaut
kix reads this output and writes the lines into a file
but the umlaut in this file is still the same character, that the shell has created.
Excel does not work with these characters.
It seems that the shell output and kix use ASCII-codes and Excel expects ANSI-codes.
When I import the csv-fiels with the option MS-DOS Mode, my characters are imported correctly.
But by default, Excel expects ANSI-Code.
 Code:
Shell-output: Jürgen
csv-file:     Jürgen
Excel-import: J"rgen

So what I need:
when I write a line into my csv-file I need to convert the MS-DOS string to ANSI, replecing all umlaut from MS-DOS format to ANSI format

Any hints?

kind regards

Jürgen


LonkeroAdministrator
(KiX Master Guru)
2009-03-20 04:11 PM
Re: DOS to ANSI

kix uses ansi.
as far as I know, ascii consist of first 127 or 128 characters.
ansi defines 256, in it's basic form.

I would guess your application uses such code-page that doesn't produce same characters as the system is set to.


LonkeroAdministrator
(KiX Master Guru)
2009-03-20 04:13 PM
Re: DOS to ANSI

hmm...
the umlaut references makes me think the shell program might even use utf.


NTDOCAdministrator
(KiX Master)
2009-03-20 05:05 PM
Re: DOS to ANSI

It imports just fine for me in Excel. You can choose what character set to use for the conversion in Excel.




WagnerJu
(Fresh Scripter)
2009-03-24 02:13 PM
Re: DOS to ANSI

 Originally Posted By: NTDOC
It imports just fine for me in Excel. You can choose what character set to use for the conversion in Excel.




Yes, when I import in Excel, I can tell Excel to use MS-DOS (PC-8) Format.
But when I just open the CSV-file, Excel opens with this file without asking for proper codepage.

I just wrote a small function, that converts umlaut from PC-8 to ANSI. and this way it works. But I hoped, to find an easier way.
 Code:
Function convert($input)
	$output=$input
	do
		$pos=instr($output,"á")
		if $pos>0
			$output=left($output,$pos-1)+"ß"+substr($output,$pos+1)
		endif
	until $pos=0			
	do
		$pos=instr($output,"")
		if $pos>0
			$output=left($output,$pos-1)+"ü"+substr($output,$pos+1)
		endif
	until $pos=0			
	do
		$pos=instr($output,"„")
		if $pos>0
			$output=left($output,$pos-1)+"ä"+substr($output,$pos+1)
		endif
	until $pos=0		
	do
		$pos=instr($output,"”")
		if $pos>0
			$output=left($output,$pos-1)+"ö"+substr($output,$pos+1)
		endif
	until $pos=0		
	do
		$pos=instr($output,"™")
		if $pos>0
			$output=left($output,$pos-1)+"Ö"+substr($output,$pos+1)
		endif
	until $pos=0		
	do
		$pos=instr($output,"Ž")
		if $pos>0
			$output=left($output,$pos-1)+"Ä"+substr($output,$pos+1)
		endif
	until $pos=0		
	do
		$pos=instr($output,"š")
		if $pos>0
			$output=left($output,$pos-1)+"Ü"+substr($output,$pos+1)
		endif
	until $pos=0			

	$convert=$output
EndFunction


thanks for helping

Jürgen


NTDOCAdministrator
(KiX Master)
2009-03-24 11:51 PM
Re: DOS to ANSI

Well I suppose if you're trying to fully automate it then you'd need to change the default importer action in Excel if possible. That or fully open and import, etc from script.

LonkeroAdministrator
(KiX Master Guru)
2009-03-25 10:24 AM
Re: DOS to ANSI

iirc, excel does some assumptions on the file format based on the file-extension.
.csv imo is handled totally wrong.
.txt is only thing you can surely make work in excel, but requires user input and thus,

what doc said about directly writing to the sheet might be cleanest option.


LonkeroAdministrator
(KiX Master Guru)
2009-03-25 10:32 AM
Re: DOS to ANSI

btw, Jürgen...
could you modify your convert a bit.
I wanna see what asc() codes you get with these failing characters.
so, for example try this:
 Code:
	code removed, see next post	


that is, add asc(substr(str,instr())) for these characters to the output to see, what the codes are, so you/I/we can determine, what character set is actually used in the original input.

It indeed looks weird that basic character of space is actually "ü"... doesn't make any sense. I thought the base characters are always the same.
anyway, once you provide the charcodes, we will see what really is happening here.


LonkeroAdministrator
(KiX Master Guru)
2009-03-25 10:36 AM
Re: DOS to ANSI

oh, even more output would be better.
instead use this:
 Code:
	do
		$pos=instr($output,"")
		if $pos>0
			$output=left($output,$pos-1)+"ü ("+ asc(substr($output,instr($output,""))) + " = " + asc("ü") + ")"+substr($output,$pos+1)
		endif
	until $pos=0	


LonkeroAdministrator
(KiX Master Guru)
2009-03-26 03:19 PM
Re: DOS to ANSI

jürgen, you still there?