Page 1 of 1 1
Topic Options
#193038 - 2009-03-20 02:56 PM DOS to ANSI
WagnerJu Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 6
Loc: Germany
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

Top
#193042 - 2009-03-20 04:11 PM Re: DOS to ANSI [Re: WagnerJu]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#193043 - 2009-03-20 04:13 PM Re: DOS to ANSI [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm...
the umlaut references makes me think the shell program might even use utf.
_________________________
!

download KiXnet

Top
#193046 - 2009-03-20 05:05 PM Re: DOS to ANSI [Re: Lonkero]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
It imports just fine for me in Excel. You can choose what character set to use for the conversion in Excel.



Top
#193117 - 2009-03-24 02:13 PM Re: DOS to ANSI [Re: NTDOC]
WagnerJu Offline
Fresh Scripter

Registered: 2009-03-20
Posts: 6
Loc: Germany
 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

Top
#193136 - 2009-03-24 11:51 PM Re: DOS to ANSI [Re: WagnerJu]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
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.
Top
#193147 - 2009-03-25 10:24 AM Re: DOS to ANSI [Re: NTDOC]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#193148 - 2009-03-25 10:32 AM Re: DOS to ANSI [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.


Edited by Lonkero (2009-03-25 10:37 AM)
_________________________
!

download KiXnet

Top
#193150 - 2009-03-25 10:36 AM Re: DOS to ANSI [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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	
_________________________
!

download KiXnet

Top
#193180 - 2009-03-26 03:19 PM Re: DOS to ANSI [Re: Lonkero]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jürgen, you still there?
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.061 seconds in which 0.026 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org