TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dubb on November 04, 2019, 12:36:20 PM
-
When creating a tab delimited text file I
(princ "A\tB\tC\n1\t2\t3
as a .csv file. However when I open it up in excel it doesn't recognize it. So then I found out how to save the file as unicode using notepad. After doing so, it open up correctly in excel.
How do I saveas or make the file a unicode type file in autolisp without actually writing unicode characters?
-
Try to convert using iconv https://en.wikipedia.org/wiki/Iconv
-
I'm not sure that this will solve the problem of Excel recognising the file, but nevertheless this thread (https://www.theswamp.org/index.php?topic=39617.0) demonstrates how to read/write Unicode files.
-
You know. I Googled it and led to a similar post. It was a matter of figuring out how it was used. But this worked. Thanks for sharing.
I'm not sure that this will solve the problem of Excel recognising the file, but nevertheless this thread (https://www.theswamp.org/index.php?topic=39617.0) demonstrates how to read/write Unicode files.
-
Have you tried this way using the chr method.
(setq fo (open (setq fname "d:\\acadtemp\\testab.txt") "w"))
(write-line (strcat "a" (chr 9) "b" (Chr 9) "c") fo)
(write-line (strcat "a" (chr 9) (chr 9) "b" (Chr 9) (chr 9) "c") fo)
(close fo)
a b c
a b c
(write-line (strcat "f" (chr 9) (chr 9) "g" (Chr 9) (chr 9) "h" (chr 13) "d" (chr 9) (chr 9) "e") fo)
a b c
a b c
f g h
d e
-
I haven't. But it looks way complicated. The actual string I'm writing contains a lot of text. Looks like I would have to convert each letter using this method. That's interesting though, I might have use for it.
Have you tried this way using the chr method.
(setq fo (open (setq fname "d:\\acadtemp\\testab.txt") "w"))
(write-line (strcat "a" (chr 9) "b" (Chr 9) "c") fo)
(write-line (strcat "a" (chr 9) (chr 9) "b" (Chr 9) (chr 9) "c") fo)
(close fo)
a b c
a b c
(write-line (strcat "f" (chr 9) (chr 9) "g" (Chr 9) (chr 9) "h" (chr 13) "d" (chr 9) (chr 9) "e") fo)
a b c
a b c
f g h
d e
-
Looks like I would have to convert each letter using this method.
Al isn't converting any text. 9 is the ascii code for tab. He's just using (chr 9) instead of "\t".
-
Looks like I would have to convert each letter using this method.
Al isn't converting any text. 9 is the ascii code for tab. He's just using (chr 9) instead of "\t".
As such, there will be no difference in the outcome since:
-
Looks like I would have to convert each letter using this method.
Al isn't converting any text. 9 is the ascii code for tab. He's just using (chr 9) instead of "\t".
As such, there will be no difference in the outcome since:
Good point. But since Al is using writeline instead of princ, that should produce the proper format for a txt file, correct?
-
Thought I better test and worked in excel, recognised the tabs.
A Bit more
(setq fo (open (setq fname "d:\\acadtemp\\testab.txt") "w"))
(write-line (strcat "a" (chr 9) "b" (Chr 9) "c") fo)
(write-line (strcat "a" (chr 9) (chr 9) "b" (Chr 9) (chr 9) "c") fo)
(write-line (strcat "f" (chr 9) (chr 9) "g" (Chr 9) (chr 9) "h" (chr 13) "d" (chr 9) (chr 9) "e") fo)
(close fo)
(command "start" "Excel d:\\acadtemp\\testab.txt")