Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

numbers don't show german umlaut but quick view does

I do have a problem opening CSV files in Numbers.


I have a shared folder with VirtualBox. The virtual HD is formatted in FAT32. With Windows I created a CSV file which contains german umlauts like ÄÖÜ.


When I open the CSV with the "quick view" (press space when file is selected in finder, the CSV is displayed as a nice Table and all Umlauts are OK.


When I double click the CSV file to open it in Numbers, the Umlauts are not displayed. Opening in Text Edit is the same result, no Umlauts.

ö = ^

ß = fl

ü = ¸

ä =


I think this is an encoding problem, but why is "quick view" displaying it correct. I'm confused.



Thanks for any help.

iMac (27-inch Mid 2011), OS X Mountain Lion (10.8.3), Numbers 09 Version 2.3 (554)

Posted on Apr 25, 2013 12:26 PM

Reply
Question marked as Best reply

Posted on Apr 26, 2013 1:18 AM

Hello


It seems the CSV file is in ISO-8859-1 and Numbers.app and TextEdit.app are interpreting it as MacRoman.


One way to convert ISO-8859-1 text to UTF-8 text is to use TextEdit.app as follows -


a) In TextEdit's Preferences > Open and Save > Plain Text File Encoding, set the encoding for "Opening files:" to "Western (Windows Latin 1) and the encoding for "Saving files:" to "Unicode (UTF-8)".


b) Open the CSV file using TextEdit and save it as different file. (I don't know about autosave & versions stupidities at all and you might need to go through tedious steps to perform simple save-as...)



Now the resultant file is in UTF-8 (with the extended attribute set accordingly). Try opening it in Numbers.app.


There're many ways to convert text encoding and if you need batch conversion of many files it can be done in a few lines of shell script.


Regrads,

H

5 replies
Question marked as Best reply

Apr 26, 2013 1:18 AM in response to applevol

Hello


It seems the CSV file is in ISO-8859-1 and Numbers.app and TextEdit.app are interpreting it as MacRoman.


One way to convert ISO-8859-1 text to UTF-8 text is to use TextEdit.app as follows -


a) In TextEdit's Preferences > Open and Save > Plain Text File Encoding, set the encoding for "Opening files:" to "Western (Windows Latin 1) and the encoding for "Saving files:" to "Unicode (UTF-8)".


b) Open the CSV file using TextEdit and save it as different file. (I don't know about autosave & versions stupidities at all and you might need to go through tedious steps to perform simple save-as...)



Now the resultant file is in UTF-8 (with the extended attribute set accordingly). Try opening it in Numbers.app.


There're many ways to convert text encoding and if you need batch conversion of many files it can be done in a few lines of shell script.


Regrads,

H

Apr 28, 2013 1:18 PM in response to applevol

Hello


I cannot find any encoding settings for opening files in Numbers 09.

A simple and obvious solution would be to save CSV file in UTF-8 in FAT32 volume in VirtualBox if possible.


One other method is to copy the CSV file to HFS+ volume and set its extended attributes to specify its text encoding. This method is only changing the metadata of the file and so is less intrusive than to convert the data itself to different text encoding. When text encoding extended attribute is properly set, Numbers 09 (and TextEdit.app set to use "Automatic" encoding option in opening files) will open it in the specified text encoding.


The following AppleScript script might help to set the extended attributes (OSX 10.5 or later only). Recipe is as follows.


A1) Open /Applications/Utilities/AppleScript Editor.app, copy the code of set_latin1_xattr.applescript listed below and save it as application (bundle) in the folder where target CSV files reside.


A2) Double click the saved applet and it will set the com.apple.TextEncoding extended attribute of the *.csv and *.txt files in the same folder where the applet resides to Latin 1 when they are recognised as 'ISO-8859 text' by file(1) command.



-- set_latin1_xattr.applescript
_main()
on _main()
    set p2m to (path to me)'s POSIX path
    if p2m ends with "/" then set p2m to p2m's text 1 thru -2
    
    set sh to "
# set current directory to parent directory of script (or die)
cd \"${0%/*}\" || exit 1

# add com.apple.TextEnncoding xattr for Latin-1
# for *.csv and *.txt files, of which file info contains 'ISO-8859 text', in current directory
for f in *.{csv,txt}
do
    if [[ $(file \"$f\") =~ 'ISO-8859 text' ]]
    then
        xattr -w com.apple.TextEncoding \"WINDOWS-1252;$((0x0500))\" \"$f\"
    fi
done
"
    do shell script "/bin/bash -c " & sh's quoted form & " " & p2m's quoted form
end _main



Another method is to convert the text encoding itself as you have already done using TextEdit.app.

The following AppleScript might help to convert text encoding from latin-1 to utf-8 in bulk. Recipe is basically the same as the above.


B1) Open /Applications/Utilities/AppleScript Editor.app, copy the code of convert_latin1_to_utf8.applescript listed below and save it as application (bundle) in the folder where target CSV files reside.


B2) Double click the saved applet and it will convert the text encoding of the *.csv and *.txt files in the same folder where the applet resides to UTF-8 when they are recognised as 'ISO-8859 text' by file(1) command. Also it sets the extended attribute for text encoding accordingly.



-- convert_latin1_to_utf8.applescript
_main()
on _main()
    set p2m to (path to me)'s POSIX path
    if p2m ends with "/" then set p2m to p2m's text 1 thru -2
    
    set sh to "
# set current directory to parent directory of script (or die)
cd \"${0%/*}\" || exit 1

# make temporary directory
temp=$(mktemp -d /tmp/\"${0##*/}\".XXXXXX) || exit 1

# convert text encoding from ISO-8859-1 to UTF-8
# for *.csv and *.txt files, of which file info contains 'ISO-8859 text', in current directory
for f in *.{csv,txt}
do
    if [[ $(file \"$f\") =~ 'ISO-8859 text' ]]
    then
        iconv -f ISO-8859-1 -t UTF-8 \"$f\" > \"$temp/$f\" \\
        && xattr -w com.apple.TextEncoding \"UTF-8;$((0x08000100))\" \"$temp/$f\" \\
        && mv -f \"$temp/$f\" \"$f\"
    fi
done

# clean up temporary directory
rm -rf \"$temp\"
"
    do shell script "/bin/bash -c " & sh's quoted form & " " & p2m's quoted form
end _main


Note that the extended attribute is not supported in FAT32 and so the above methods only work in HFS+ formatted volume.

Scripts are briefly tested with Numbers 2.0.5 under OSX 10.5.8 and 10.6.5. Please make sure you have backup CSV files before applying the above scripts.


Good luck,

H

Apr 28, 2013 7:43 PM in response to Hiroto

Hello


Here're revised versions with refined file test using mime type.


All the best,

H


-- set_latin1_xattr.applescript
_main()
on _main()
    set p2m to (path to me)'s POSIX path
    if p2m ends with "/" then set p2m to p2m's text 1 thru -2
    
    set sh to "
# set current directory to parent directory of script (or die)
cd \"${0%/*}\" || exit 1

# add com.apple.TextEnncoding xattr for Latin-1
# for *.csv and *.txt files, of which file mime type matches 'text/plain; charset=iso-8859-1', in current directory
for f in *.{csv,txt}
do
    if [[ $(file -I \"$f\") =~ 'text/plain; charset=iso-8859-1' ]]
    then
        xattr -w com.apple.TextEncoding \"WINDOWS-1252;$((0x0500))\" \"$f\"
    fi
done
"
    do shell script "/bin/bash -c " & sh's quoted form & " " & p2m's quoted form
end _main



-- convert_latin1_to_utf8.applescript
_main()
on _main()
    set p2m to (path to me)'s POSIX path
    if p2m ends with "/" then set p2m to p2m's text 1 thru -2
    
    set sh to "
# set current directory to parent directory of script (or die)
cd \"${0%/*}\" || exit 1

# make temporary directory
temp=$(mktemp -d /tmp/\"${0##*/}\".XXXXXX) || exit 1

# convert text encoding from ISO-8859-1 to UTF-8
# for *.csv and *.txt files, of which file mime type matches 'text/plain; charset=iso-8859-1', in current directory
for f in *.{csv,txt}
do
    if [[ $(file -I \"$f\") =~ 'text/plain; charset=iso-8859-1' ]]
    then
        iconv -f ISO-8859-1 -t UTF-8 \"$f\" > \"$temp/$f\" \\
        && xattr -w com.apple.TextEncoding \"UTF-8;$((0x08000100))\" \"$temp/$f\" \\
        && mv -f \"$temp/$f\" \"$f\"
    fi
done

# clean up temporary directory
rm -rf \"$temp\"
"
    do shell script "/bin/bash -c " & sh's quoted form & " " & p2m's quoted form
end _main

numbers don't show german umlaut but quick view does

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.