Handling tab delimited files.

How do I import an Exel tab delimited(.xls) file into Numbers09?

Mac mini, Mac OS X (10.6.6)

Posted on Jan 21, 2011 7:22 AM

Reply
30 replies

Mar 27, 2011 2:46 PM in response to a brody

When somebody send such a file to my mailbox, it's because he received a doc which he can't decipher. He doesn't know the way the doc was created by its author.

I often wrote that polite beeings, take care of their correspondants equipment. It seems that some are truly impolite and send documents which require extraneous work to be usable.

The one encoded in Utf 16 required a lot of manual actions when I opened it in LibreOffice.
As I'm not fluent with clones of Office, two problems were not solved:
(1) how may I activate a function resembling to the wrap one which display the cell contents in several lines.
(2) how may I get rid of the character used to separate thousands. In the original which used the decimal comma, the thousand separator was period which is wrong given French rules.

All in All, using the script which I posted in this forum was faster to open it in Numbers than the opening in an Excel clone.

But, to return to your question, the correspondants which sent me such files always wrote that the docs were created by Excel. I was thinking that the extension is automatically added but I discovered recently that
(1) we may disable the tool appending the extension. This open the door to wrong manual extension appending.
(2) at least the XL clones default to the extension .csv for text files created with TAB used to separate the values.

Yvan KOENIG (VALLAURIS, France) dimanche 27 mars 2011 23:46:06

Mar 27, 2011 5:44 PM in response to KOENIG Yvan

You still haven't answered the question. Maybe I should phrase it differently. And your statement kind of reveals you know the answer.

(1) we may disable the tool appending the extension. This open the door to wrong manual extension appending.


This is the point I'm trying to say. Why approach the solution to this problem immediately by changing the extension from the Finder? This does not guarantee (unless we understand the person asking the question), that we'll end up with a properly delimited text file. I say, first make sure the file you are using is a text file, and just not an Excel file whose format hasn't been changed, before attempting to rename it. Just because a poster randomly says: "it is a tab delimited XLS file" does not mean it is a text file. I think this was the real point that the thread:

http://discussions.apple.com/thread.jspa?threadID=2792374&tstart=0

got started with. We assume we know too much about the file before we begin helping the person. We can not. An XLS file by its very nature should not normally be a tab delimited file, unless the person has force changed the extension in the first place. So when encountering such a question, as people who have answered many questions on this board, I recommend we approach it with more subtlety, and check and recheck our facts before making suggestions. Now did
jaendre send you a file at the beginning of this thread? If they did not, why are you approaching it with the same solution as someone who might have?

Mar 28, 2011 12:42 AM in response to a brody

When I receive a file which its owner can't open, the first thing which I do is to look its internals with an hexadecimal editor. This is what I posted in my late message.
If you took time to look at it, you know that it's clearly not a document with an Excel structure.

It's just a text file with TABs used to separate values.
For info, TABs are stored as $09 (old fashioned text files or Utf8 ones) or $0009 (Utf16 files).
I'm not completely fool. I don't rename as CSV a file using the TAB to separate values. Even if this file was created and named automatically by Excel, the extension may be wrong. I tested the behavior of every Excel clones which I own. All of them name tab separated values files with the CSV extension if we leave them naming the doc automatically.
What seems to be the result of the document author wrong typing is the fact that a document with the .xls extension prove to be in fact a text file (txt or csv doesn't matter on this point).

At least the XL clones, when they are set to name automatically the documents use an extension of the xls family when the documents contain the description of cells and formulas : living spreadsheets.
When they are asked to build text files storing only values or some display attributes they apply extensions in the range : {csv, dif, html}

User uploaded file

This thread is entitled "Handling tab delimited files" so, it was logical to assume that the OP was knowing that the document which he received is not using the excel structure.
For the second asker, the problem may differ but if we must guess that askers are unable to read titles of threads, we may leave the forums.

Yvan KOENIG (VALLAURIS, France) lundi 28 mars 2011 09:42:18

Mar 28, 2011 11:56 AM in response to KOENIG Yvan

Help me with a simple solution, please. I am working on my taxes, and the download of a report from e-trade comes with the extension "cvs.xls". I called e-trade, and they don't have technical support to solve this problem. I would like the file to be in columns, so that I can sort by date, alphabet, etc. I do not have Excel on this machine, I generally use Numbers as my spreadsheet software.

I am not very techie, but there must be a way to do this without too much manipulation, I hope.

Mar 29, 2011 1:17 AM in response to monica217

Hello monica

I must apologize

I didn't took cvare that you just entered the thread (and the forum).
I answered as if you were one of the askers to which I had already asked to send their offending file.

So, forget the 'already offered' component of my proposal.
You may send your file to my mailbox to allow me to decipher it.

Click my blue name to get my address.

Yvan KOENIG (VALLAURIS, France) mardi 29 mars 2011 10:17:19

Mar 29, 2011 1:47 PM in response to KOENIG Yvan

The file the original poster in this thread sent you was a strange document indeed. The one I mention in the one about opening ms formatted files definitely get sent down by Salesforce with an extension of .xls. I have set the extension of .xls and the extension of .csv to be opened by Numbers. But when numbers opens it, all data for a given row is in the first cell in the column. If others are also having problems opening .xls files (as I believe they've indicated) they may also be having the problem I'm having.

Mar 29, 2011 1:58 PM in response to monica217

Monica,

You didn't say what is happening and what needs to be solved. Is it not opening in Numbers at all or is it putting everything into a single column?

First thing I would try is removing the .xls from the filename. Then open it with Numbers and see what happens. If it is separated into columns, look it over carefully to ensure no problems with dates or anything having been converted to some other format.

If everything is in one column, maybe it is actually a tab delimited file and not a comma separated file. If so, open it in TextEdit, select and copy all the text, and paste it into a blank Numbers table.

Mar 29, 2011 2:19 PM in response to Badunit

I'm going to move my question here because it's similar. Or at least re-post it here. It's not a csv file, though I can export those and open them without trouble; it SAYS it's in .xls format, but as you can see from the line I posted below, it's really in html but supposed to be opened in excel. When I change the file type to .htm, it opens nicely in the browser, but when I copy and paste THAT into numbers, it all goes in neatly (no html tags) in the first column, each line holding one CELL of data. I SUPPOSE I could now transpose it, but what I'd have would be the equivalent of the csv file. No subtotals etc.

here's my problem:

I use a cloud-computing app, Salesforce, to maintain some databases. The report module, which produces nice-looking formatted reports, allows you to export the data as .csv files, which can be opened without trouble by Numbers. It also allows you to export them (formatting intact) as .xls files, which are (according to their first line) in this vnd.ms-excel.numberformat. I recently downloaded a trial of Microsoft Office, and those files were opened without trouble by excel (formatting intact).

Is there any way to open them in Numbers so that the formatting remains? Here is a sample lines: it's obviously html code but I can't get Numbers to read it as that.

"<tr><td style=""vnd.ms-excel.numberformat:@"">xx Durst Membership Donation - 03/05/2010</td><td align=right>5.00</td><td align=right>3/5/2010</td><td style=""vnd.ms-excel.numberformat:@"">xx Durst Household</td><td style=""vnd.ms-excel.numberformat:@"">Membership 2010</td></tr>"

Mar 30, 2011 1:17 AM in response to briegull

May you send a sample file to my mailbox ?
I wish to look in its internals to see if it defines somewhere the structure of the table.

What is sure is that you can't open this kind of doc directly with Numbers.
Maybe there is a way to decipher the contents with an AppleScript.

Click my blue name to get my address.

Yvan KOENIG (VALLAURIS, France) mercredi 30 mars 2011 10:17:18

Mar 30, 2011 8:28 AM in response to briegull

As always, with the file it's easy to build an answer.

This simple script will do the trick.

Badunit was on the good track.

The easier way to do the job was to open the file with TextEdit then transfer the three created tables in a Numbers document.

--

--[SCRIPT openhtmlxls]
(*
Enregistrer le script en tant que Script ou Application : openhtmlxls.xxx
déplacer le fichier ainsi créé dans le dossier
<VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:
Aller au menu Scripts , choisir Numbers puis choisir “openhtmlxls”
Le script demande de sélectionner un fichier Excel de structure html.
Il l’ouvre dans TextEdit, sélectionne tout puis copie dans le Presse-papiers.
Il crée un nouveau document à partir du modèle "Vide" de Numbers.
Il supprime la table crée par défaut et colle.
--=====
L’aide du Finder explique:
L’Utilitaire AppleScript permet d’activer le Menu des scripts :
Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
Cochez la case “Afficher le menu des scripts dans la barre de menus”.
Sous 10.6.x,
aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript
puis cocher la case “Afficher le menu des scripts dans la barre des menus”.
--=====
Save the script as a Script or an Application : openhtmlxls.xxx
Move the newly created file into the folder:
<startup Volume>:Users:<yourAccount>:Library:Scripts:
Go to the Scripts Menu, choose Numbers, then choose “openhtmlxls”
The script ask you to select an Excel document structured as html.
It open it in TextEdit, Select All and Copy to the clipboard.
It create a new document from the Numbers' blank template.
It delete the default table then paste.
--=====
The Finder’s Help explains:
To make the Script menu appear:
Open the AppleScript utility located in Applications/AppleScript.
Select the “Show Script Menu in menu bar” checkbox.
Under 10.6.x,
go to the General panel of AppleScript Editor’s Preferences dialog box
and check the “Show Script menu in menu bar” option.
--=====
Yvan KOENIG (VALLAURIS, France)
2011/03/30
*)
--=====
on run
run script doyourduty
-- my doyourduty()
end run
--=====
script doyourduty
-- on doyourduty()

local unxlshtml, myNewDoc

my activateGUIscripting()

tell application (path to frontmost application as text)
if my parleAnglais() then
set unxlshtml to choose file with prompt "Choose an html xls file" of type "com.microsoft.excel.xls" without invisibles
else
set unxlshtml to choose file with prompt "Choisir un fichier Excel de type Html" of type "com.microsoft.excel.xls" without invisibles
end if -- parleAnglais
end tell
-- set unxlshtml to ("" & (path to desktop & "report1301488888645.xls")) as alias

tell application "TextEdit"
open unxlshtml
my raccourci("TextEdit", "a", "c") -- Select All
my raccourci("TextEdit", "c", "c") -- Copy
close document 1
end tell

set myNewDoc to my makeAnIworkDoc("Numbers")
tell application "Numbers" to tell document myNewDoc to tell sheet 1
delete table 1
end tell
my raccourci("Numbers", "v", "c") -- Paste
-- end doyourduty
end script
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
on activateGUIscripting()
(* to be sure than GUI scripting will be active *)
tell application "System Events"
if not (UI elements enabled) then set (UI elements enabled) to true
end tell
end activateGUIscripting
--=====
(*
Creates a new iWork document from the Blank template and returns its name.
example:
set myNewDoc to my makeAnIworkDoc(theApp)
*)
on makeAnIworkDoc(the_app)
local maybe, pathto_theApp, nb_doc, doc_name
if the_app is "Pages" then
tell application "Pages"
set nb_doc to count of documents
make new document with properties {template name:item 1 of templates}
end tell
else if the_app is "Numbers" then
tell application "System Events" to set maybe to the_app is in title of every application process
if not maybe then tell application theApp to activate
tell application "System Events"
set pathto_theApp to get application file of application process the_app
end tell
tell application "Numbers"
set nb_doc to count of documents
open ((pathto_theApp as text) & "Contents:Resources:Templates:Blank.nmbtemplate:")
end tell
else
if my parleAnglais(theApp) then
error "The application “" & the_app & "“ is not accepted !"
else
error "l’application « " & the_app & " » n’est pas gérée !"
end if
end if

tell application the_app
repeat until (count of documents) > nb_doc
delay 0.1
end repeat
set doc_name to name of document 1
end tell -- the_App
return doc_name
end makeAnIworkDoc
--=====
(*
==== Uses GUIscripting ====
*)
(*
This handler may be used to 'type' text, invisible characters if the third parameter is an empty string.
It may be used to 'type' keyboard raccourcis if the third parameter describe the required modifier keys.
I changed its name « shortcut » to « raccourci » to get rid of a name conflict in Smile.
*)
on raccourci(a, t, d)
local k
tell application a to activate
tell application "System Events" to tell application process a
set frontmost to true
try
t * 1
if d is "" then
key code t
else if d is "c" then
key code t using {command down}
else if d is "a" then
key code t using {option down}
else if d is "k" then
key code t using {control down}
else if d is "s" then
key code t using {shift down}
else if d is in {"ac", "ca"} then
key code t using {command down, option down}
else if d is in {"as", "sa"} then
key code t using {shift down, option down}
else if d is in {"sc", "cs"} then
key code t using {command down, shift down}
else if d is in {"kc", "ck"} then
key code t using {command down, control down}
else if d is in {"ks", "sk"} then
key code t using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
key code t using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
key code t using {command down, shift down, option down}
end if
on error
repeat with k in t
if d is "" then
keystroke (k as text)
else if d is "c" then
keystroke (k as text) using {command down}
else if d is "a" then
keystroke k using {option down}
else if d is "k" then
keystroke (k as text) using {control down}
else if d is "s" then
keystroke k using {shift down}
else if d is in {"ac", "ca"} then
keystroke (k as text) using {command down, option down}
else if d is in {"as", "sa"} then
keystroke (k as text) using {shift down, option down}
else if d is in {"sc", "cs"} then
keystroke (k as text) using {command down, shift down}
else if d is in {"kc", "ck"} then
keystroke (k as text) using {command down, control down}
else if d is in {"ks", "sk"} then
keystroke (k as text) using {shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "k" then
keystroke (k as text) using {command down, shift down, control down}
else if (d contains "c") and (d contains "s") and d contains "a" then
keystroke (k as text) using {command down, shift down, option down}
end if
end repeat
end try
end tell
end raccourci
--=====
--[/SCRIPT]
--


Yvan KOENIG (VALLAURIS, France) mercredi 30 mars 2011 17:28:02

Mar 30, 2011 9:35 AM in response to KOENIG Yvan

Thank you so very much, Yvan. This is a problem that has vexed me for a while.

Without the script, though, I had tried opening it in text edit, copying it, and pasting it into Numbers. And the cells for a given record went down, not across, one below another, record after record all in column A. They still do.. Maybe that's some setting I can't find in Numbers but it worked with your script!!

Again, this worked beautifully. Thank you User uploaded file

Mar 30, 2011 10:05 AM in response to briegull

briegull wrote:
Thank you so very much, Yvan. This is a problem that has vexed me for a while.

Without the script, though, I had tried opening it in text edit, copying it, and pasting it into Numbers. And the cells for a given record went down, not across, one below another, record after record all in column A. They still do.. Maybe that's some setting I can't find in Numbers but it worked with your script!!


I guess that you pasted in an existing table.

If you read carefully the explanations given in the script, you will learn that it removes the default table then paste in the empty sheet creating three new tables.

Yvan KOENIG (VALLAURIS, France) mercredi 30 mars 2011 19:05:03

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Handling tab delimited files.

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