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

Maximum number of rows and/or columns exceeded

I just tried to create a Numbers spreadsheet - by opening a TXT file with tab delimiters, Numbers only read in 29549 of the 43546 rows (and each row had 30 columns), and then put up a message that it said it couldn't do more than 65535 rows and 255 columns, neither of which had really happened yet. It would appear that Numbers can't really input what it claims or the manual says it is supposed to be able to do.


What is the largest array anyone has ever successfully imported into Numbers?


Yes - I know it gets really slow when you have this many cells, but I really don't want to have to buy Excel for obvious reasons. What I need to do is just find some minimum and maximum values from a whole bunch of data.


Thanks.


-Bob


ps - using Numbers from iWork `09 on a MacBook with OS X 10.7.2

Intel Mac, Mac OS X (10.7.2)

Posted on Jan 2, 2012 9:56 PM

Reply
14 replies

Jan 2, 2012 10:32 PM in response to DeepYogurt

Hi Bob,


You might be happier with OpenOffice.org or LibreOffice, both open source applications that will easily handle files of that size. Both are downloadable and useable at no charge, although donations are requested by at least one of the sites. A third choice is NeoOffice, but they've started to require (rather than request) a minimum donation within the last year to get the most recent version.


The links above will take you to each download site.


Regards,

Barry

Jan 3, 2012 3:07 AM in response to DeepYogurt

I guess that there is an other problem than the count of rows.


I made a quick test.

I used a script to build a 65535 lines text file and it was imported flawlessly :

User uploaded file


Maybe your original text file contain line Return characters in cells creating extraneous rows during the import process.


I wish to add that the limit 65535*255 is a theoric one.

An other limit may apply : the available RAM.



Yvan KOENIG (VALLAURIS, France) mardi 3 janvier 2012

iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

My iDisk is : http://public.me.com/koenigyvan

Please : Search for questions similar to your own before submitting them to the community


For iWork's applications dedicated to iOS, go to :

https://discussions.apple.com/community/app_store/iwork_for_ios

Jan 3, 2012 2:50 PM in response to KOENIG Yvan

At the time I had about 2-3GB of free memory acording to Activity Monitor - the raw data file was a little under 10MB, so doubt if memory was an issue. There were not a bunch of extra blank lines so that doesn't seem to be it either.


If Koenig was able to create a script to create a 65K row file, then not sure what the problem might be.


The file I tried to import is a public file - if you would like to try and import it go to http://tdc-www.cfa.harvard.edu/2mrs/ and download the 2MRS catalog zip file and then import the 2mrs_1175_done.dat file (after converting multiple spaces to one tab and renaming to 2mrs_1175_done.txt so that it can be opened in Numbers (the file is in the folder named "catalog"). The file has about 44K lines and 30 columns - both well under the limit.


Let me know if you have a similar problem. If you don't then I'm even more puzzled as to what the problem might be.


Thanks for helping...


-Bob

Jan 3, 2012 8:22 PM in response to DeepYogurt

HI Bob,


I opened the .dat file in TextEdit, removed the information lines at the top (tagged with a #), leaving only the field names and the data. Then:

  • I used Find/replace in TextEdit to replace all of the double spaces with single spaces.
  • Repeated until F/R reported non found.
  • Replaced all the single spaces with tabs
  • Saved with the .txt extension


I got the same 'too large' message on trying to open the .txt file with Numbers. 😟


OpenOffice.org successfully opened the .txt file, but into a Write document, not a Calc one. 😟


Back in TextEdit, I Selected All, then copied.


I opened a new blank Numbers document, selected cell A1 and Pasted.


After a lengthy wait, the beachball finally disappeared and the data appeared in the table—all 43534 rows of it. There also appeared to be two empty columns beyond the end of the data rows. I didn't scan the sheet to determine what had caused them.


Several minutes into the wait, I thought that deleting the header column (and perhaps the header row) from the default Blank table might have been a good idea. I haven't tested, but removing the header cells should make at least a slight reduction in the delay between actions and responses.


Back in Text Edit, I replaced all of the tabs with commas, and saved the file with the .csv extension.


Attempting to open this with Numbers produced the same "the document is too large" message.


With OpenOffice.org, I noticed the File Type pop-up menu below the file list in the Open dialogue. About a page down the list, in the spreadsheet section and between the groups for Excel 97/2000 and the group for Excel 2007 was an Aha!—"Text CSV (*.csv, *.txt, *.xls)"—which I selected, and proceeded to opening the .csv version of the file. One more dialogue box to choose the separator character—Hmmm..., comma was selected, but another choice was "tab"...


The .csv file opened within about a minute. And, after I had closed that file, OpenOffice.org successfully opened the tab separated .txt file.


I think I'll stay with my previous comment—OOo, or one of its offshoots, might be the better choice here.


Regards,

Barry


iMac, 2.7 GHz Core 2 Duo, OSX v10.5.8

Jan 4, 2012 7:10 AM in response to Barry

Hello


I did the same under 10.7.2.

I got the same results.

So I will file a bug report.

I will try to write a script doing the space cleaning then opening a blank spreadsheet and pasting in the table.

At least, it will give a neat workaround.


Yvan KOENIG (VALLAURIS, France) mercredi 4 janvier 2012

iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

My iDisk is : http://public.me.com/koenigyvan

Please : Search for questions similar to your own before submitting them to the community


For iWork's applications dedicated to iOS, go to :

https://discussions.apple.com/community/app_store/iwork_for_ios

Jan 4, 2012 8:00 AM in response to Barry

Hello


At the end of lines are chunks of 20 space characters.

You got two empty columns because you start your replacement with a string of less than 20 spaces but more than 10.


My script was supposed to be ready but I hit a limit of what AppleScript may achieve.

So I must treat the datas by chunks of 10 thousands or 20 thousands of lines so I need more time.


Yvan KOENIG (VALLAURIS, France) mercredi 4 janvier 2012

iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

My iDisk is : http://public.me.com/koenigyvan

Please : Search for questions similar to your own before submitting them to the community


For iWork's applications dedicated to iOS, go to :

https://discussions.apple.com/community/app_store/iwork_for_ios

Jan 4, 2012 10:46 AM in response to KOENIG Yvan

"At the end of lines are chunks of 20 space characters.

You got two empty columns because you start your replacement with a string of less than 20 spaces but more than 10."


That would explain a single extra column, but I don't see how it explains two, unless there is some other character in the first 'empty' column. When reducing the number of spaces, I used Find/Replace to replace all pairs of consecutive spaces with a single spaces, and repeated until F/R reported the two space string was not found. I don't recall how many passes that took, but the results starting with a 20 space string should have followed the pattern below (using x to represent the spaces):


start xxxxxxxxxxxxxxxxxxxx

pass 1 xxxxxxxxxx

pass 2 xxxxx

pass 3 xxx

pass 4 xx

pass 5 x

pass 6 "not found"


Regards,

Barry

Jan 4, 2012 12:36 PM in response to Barry

Thanks to both Barry and Yvan - very very much. A clever idea to do the copy/paste instead of the file open!!


One thing that I've found really handy in editing text files like this is to use the command line "vi" editor or one of it's GUI clones:


1. To remove the trailing spaces at the end of the line:


:%s/ *$//


: -- tells vi to go to command mode, or whatever they call it

% -- tells vi to apply the command to the entire file

s/ *$// -- tells vi to substitute one or more spaces at the end of the line, noted by the $, with nothing


2. To change multiple spaces into one tab character in one step:


:%s/ */ctrl-i/g


If you don't understand "vi" syntax, read the man page about "regular expression" substituions for more info. The ctrl-i is the "TAB" key. regular-expression manipulation is a really handy thing to know how to do with "vi" and has saved me countless hours over the years in doing data-file cleanup. Well worth investing the time to learn it if you have to deal with editing complicated or really large files.


Anyway, that's enough "vi" trivia for the day and thanks again to both of you for verifying that Numbers really does have the bug and thanks even more for the work-around!!!


-Bob

Jan 4, 2012 1:52 PM in response to Barry

Thanks to my script, I discovered that only the column AE is really empty.

Cell AD7055 contains the value 17.

We have no way to get a better result.


My scheme was able to explain the availability of two columns.


Assuming that lines end with 20 spaces characters.

If the first chunk of spaces used to replace is a 15 spaces one.

A 20 spaces block become a TAB + 5 spaces block which is changed later into TAB + TAB


With my script, the job on the given file require more than seven minutes.


As I know nothing about UNIX commands, I will ask help to embed the vi one :

:%s/ */ctrl-i/g

in a do Shell Script instruction.


Yvan KOENIG (VALLAURIS, France) mercredi 4 janvier 2012

iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

My iDisk is : http://public.me.com/koenigyvan

Please : Search for questions similar to your own before submitting them to the community


For iWork's applications dedicated to iOS, go to :

https://discussions.apple.com/community/app_store/iwork_for_ios

Jan 4, 2012 7:39 PM in response to DeepYogurt

Hi Bob,


Regarding vi, TextWrangler, and its 'big brother,' BBEdit, also support functions that will remove leading, trailing and extra spaces, but I so seldom need to to this that the functions slip my mind between sessions. The other factor was that the machine I was using for this doesn't have TextWrangler installed, and I didn't bother to change that for what was likely to be a one-off situation.


Thanks for the tip, though. It may be of use to someone passing by with a similar question.


Regards,

Barry

Jan 4, 2012 8:06 PM in response to KOENIG Yvan

Hi Yvan,


You wrote:


Thanks to my script, I discovered that only the column AE is really empty.

Cell AD7055 contains the value 17.


Looks like a data entry error in the original table. All of the similar entries at the ends of lines had an underscore between the final three digit number and the preceding part of the catalogue number:

e.g. ESO_431-_G_017

This one had a space: ESO_270-_G 017


Assuming that lines end with 20 spaces characters.

If the first chunk of spaces used to replace is a 15 spaces one.

A 20 spaces block become a TAB + 5 spaces block which is changed later into TAB + TAB


True enough, but I was replacing pairs of spaces with a single space. Replacing single spaces with tabs didn't happen until there were no instances of two consecutive spaces left. Had the data entry error above not been made, my Numbers table would have had a single extra column


Regards,

Barry

Jan 5, 2012 12:58 PM in response to Barry

Hello Barry

I can't guess if the value 17 creating an extraneous column is normal or the result of a data error.


For the tab count, I didn't used your scheme.

In theory, yours is better but when applied in an AppleScript is gave a wrong behavior.


Given AppleScript features, I can't treat the entire file in a single pass with standard AppleScript.

So, I must create a loop treating smaller blocks of datas.

Alas, doing that introduce a new problem.

filling the clipboard and pasting in Numbers requires a lot of time.

with your scheme, replacing spaces by TAB requires less time than the fill clipboard and paste one so there is an annoying confict on pass 2 or worst at the end of the last pass because the last block of data is small so treating it is fast and when it's done, the preceeding paste task isn't achieved.


Other annoying feature, when I create a new document by hand, I may work upon it without AutoSave action but when the doc is created thru a script, AutoSave apply and sometimes a script instruction is executed during an autosave task and in this case, the action applied to Numbers is lost.

Of course, I will report that to Apple.


Here are two versions of a script using standard AppleScript.

You will be able to run them for see.

Be patient, they require several minutes.


With the first one, I was able to treat the original document.

No need to rename it. The script accept the xxx.dat file on entry.


--{code}

--[SCRIPT huge-text-to-Numbers v1]

(*

Enregistrer le script en tant qu’application : huge-text-to-Numbers.app

Il sera très bien sur le bureau.


mode 1 :

Double clic sur “huge-text-to-Numbers.app”

Un dialogue demande de naviguer vers le fichier txt ou dat à traiter

mode 2 :

Glisser déposer l'icône du fichier texte à traiter sur celle de “huge-text-to-Numbers.app”


Dans les deux cas, le script remplace les groupes d'espaces par un caractère TAB.

Les données texte ainsi réorganisées sont collées dans un nouveau document Numbers.


--=====


Save the script as an Application : huge-text-to-Numbers.app

The Desktop would be a good location.


mode 1 :

Double click on “huge-text-to-Numbers.app”

A dialog allow to navigate to the txt or dat file to import.

mode 2 :

Drag and drop the text file icon on the “huge-text-to-Numbers.app” one.


In both cases the script replace chunks of spaces by single TAB character.

Then, the reorganized datas are pasted in a new Numbers document.


--=====


Yvan KOENIG (VALLAURIS, France)

2012-01-05

*)

(*

Use a property to fasten the script *)

property laSource : {}

property leFichier : ""


--=====


script main

local debut, spaces30, nbParagraphes, |texteTraité|, bloc, premierParagrapheDuBloc, dernierParagrapheDuBloc, blocDeTexte, spaces

my activateGUIscripting()

set debut to current date

set my laSource to every paragraph of (read leFichier)


(*

Create a string of 30 spaces characters *)

set spaces30 to ""

repeat 30 times

set spaces30 to spaces30 & space

end repeat


(*

Create a blank Numbers spreadsheet and remove the headers from the default table *)

set myNewDoc to my makeAnIworkDoc("Numbers")

tell application "Numbers" to tell document myNewDoc to tell sheet 1 to tell table 1


removerow 1


removecolumn 1

end tell


(*

Replace every chunks of spaces by a single TAB character *)

set nbParagraphes to count my laSource

set numDuBloc to 1

set premierParagrapheDuBloc to 1

repeat

set dernierParagrapheDuBloc to premierParagrapheDuBloc + 19999

if dernierParagrapheDuBloc > nbParagraphes then set dernierParagrapheDuBloc to nbParagraphes

set blocDeTexte to my recolle(itemspremierParagrapheDuBloc thru dernierParagrapheDuBloc of my laSource, return)

copy spaces30 to spaces

set nbSpaces to 30

repeat

if nbSpaces > 1 then

say "replace groups of " & nbSpaces & " spaces by tab in block " & numDuBloc

else

say "replace every single space by a tab in block " & numDuBloc

end if

set blocDeTexte to my remplace(blocDeTexte, spaces, tab)

if nbSpaces > 1 then

set spaces to text 1 thru -2 of spaces

else

exit repeat

end if

set nbSpaces to nbSpaces - 1

end repeat


say "remove tab from end of paragraphs in block " & numDuBloc

if blocDeTexte ends with tab then set blocDeTexte to text 1 thru -2 of blocDeTexte

set blocDeTexte to my remplace(blocDeTexte, tab & return, return)


tell application "Numbers" to tell document myNewDoc to tell sheet 1 to tell table 1

(*

Create the first row the insertion area *)

repeat

try


add row below last row

exit repeat

on error

delay 0.1

end try

end repeat

(*

Define the insertion area *)

repeat

try

set selection range to range (name of cell 1 of row premierParagrapheDuBloc)

exit repeat

on error

delay 0.1

end try

end repeat

end tell


(*

Copy the datas to the clipboard *)

say "Copy the datas to the clipboard"


set the clipboard toblocDeTexte

say "paste in the table"

my raccourci("Numbers", "v", "cas")


(*

tell application "Numbers" to tell document myNewDoc to tell sheet 1 to tell table 1

(*

Select the first cell of last row *)

set selection range to range (name of cell 1 of last row)

end tell

*)

if dernierParagrapheDuBloc < nbParagraphes then

set numDuBloc to numDuBloc + 1

set premierParagrapheDuBloc to dernierParagrapheDuBloc + 1

else

exit repeat

end if

end repeat

say "Done in " & ((current date) - debut) & " seconds."


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 recolle(l, d)

local oTIDs, t

set oTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to d

set t to l as text

set AppleScript's text item delimiters to oTIDs

return t

end recolle


--=====

(*

replaces every occurences of d1 by d2 in the text t

*)

on remplace(t, d1, d2)

local oTIDs, l

set oTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to d1

set l to text items of t

set AppleScript's text item delimiters to d2

set t to l as text

set AppleScript's text item delimiters to oTIDs

return t

end remplace


--=====

(*

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, path_to_the_App, nb_doc

if the_app is "Pages" then

tell application "Pages"

set nb_doc to count of documents


makenewdocumentwith properties {template name:item 1 of templates}

end tell

else if the_app is "Numbers" then

tell application "System Events" to the_app is in title of every application process

if not result then activateapplicationtheApp

tell application "System Events"

set path_to_the_App to get application file of application processthe_app

end tell

tell application "Numbers"

set nb_doc to count of documents

open ((path_to_the_App 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 applicationthe_app

repeat until (count of documents) > nb_doc

delay 0.1

end repeat

name of document 1

end tell -- the_App

return result

end makeAnIworkDoc


--=====


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


--=====

(*

==== 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


activateapplicationa

tell application "System Events" to tell application process a

set frontmost to true

try

t * 1

if d is "" then


key codet

else if d is "c" then


key codetusing {command down}

else if d is "a" then


key codetusing {option down}

else if d is "k" then


key codetusing {control down}

else if d is "s" then


key codetusing {shift down}

else if d is in {"ac", "ca"} then


key codetusing {command down, option down}

else if d is in {"as", "sa"} then


key codetusing {shift down, option down}

else if d is in {"sc", "cs"} then


key codetusing {command down, shift down}

else if d is in {"kc", "ck"} then


key codetusing {command down, control down}

else if d is in {"ks", "sk"} then


key codetusing {shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "k" then


key codetusing {command down, shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "a" then


key codetusing {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


keystrokekusing {option down}

else if d is "k" then


keystroke (k as text) using {control down}

else if d is "s" then


keystrokekusing {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


--=====


on run

set leFichier to choose file of type {"txt", "dat"} without invisible


run scriptmain

end run


--=====


on open sel

set leFichier to first item of sel

tell application "System Events"

try

set extension_du_nom to name extension of disk item (leFichier as text)

on error

set extension_du_nom to ""

end try

end tell

if extension_du_nom is in {"txt", "dat"} then


run scriptmain

else

set leFichier to ""

if my parleAnglais() then

error "The file" & return & leFichier & return & "isn’t a txt or dat one !"

else

error "Le fichier" & return & leFichier & return & "n’est pas de type .txt ou .dat !"

end if

end if

end open


--=====

--[/SCRIPT]

--{code}



The second one use your scheme to replace the space characters.

As I wrote above, it fails.

But it's interesting to run it to compare the time required to treat a block.


--{code}

--[SCRIPT huge-text-to-Numbers v2]

(*

Enregistrer le script en tant qu’application : huge-text-to-Numbers.app

Il sera très bien sur le bureau.


mode 1 :

Double clic sur “huge-text-to-Numbers.app”

Un dialogue demande de naviguer vers le fichier txt ou dat à traiter

mode 2 :

Glisser déposer l'icône du fichier texte à traiter sur celle de “huge-text-to-Numbers.app”


Dans les deux cas, le script remplace les groupes d'espaces par un caractère TAB.

Les données texte ainsi réorganisées sont collées dans un nouveau document Numbers.


--=====


Save the script as an Application : huge-text-to-Numbers.app

The Desktop would be a good location.


mode 1 :

Double click on “huge-text-to-Numbers.app”

A dialog allow to navigate to the txt or dat file to import.

mode 2 :

Drag and drop the text file icon on the “huge-text-to-Numbers.app” one.


In both cases the script replace chunks of spaces by single TAB character.

Then, the reorganized datas are pasted in a new Numbers document.


In fact, as the code which fix the text is too fast,

there is conflict with the paste task and the treatment fails.


--=====


Yvan KOENIG (VALLAURIS, France)

2012-01-05

*)

(*

Use a property to fasten the script *)

property laSource : {}

property leFichier : ""


--=====


script main


(*

Requires the properties leFichier and laSource *)

local debut, nbParagraphes, bloc, premierParagrapheDuBloc, dernierParagrapheDuBloc, blocDeTexte, spaces

my activateGUIscripting()

set debut to current date

set my laSource to every paragraph of (read leFichier)


(*

Create a blank Numbers spreadsheet and remove the headers from the default table *)

set myNewDoc to my makeAnIworkDoc("Numbers")

tell application "Numbers" to tell document myNewDoc to tell sheet 1 to tell table 1


removerow 1


removecolumn 1

end tell


(*

Replace every chunks of spaces by a single TAB character *)

set nbParagraphes to count my laSource

set numDuBloc to 1

set premierParagrapheDuBloc to 1

repeat

set dernierParagrapheDuBloc to premierParagrapheDuBloc + 9999

if dernierParagrapheDuBloc > nbParagraphes then set dernierParagrapheDuBloc to nbParagraphes

set blocDeTexte to my recolle(itemspremierParagrapheDuBloc thru dernierParagrapheDuBloc of my laSource, return)


say "Start treatment of rows " & premierParagrapheDuBloc & " to " & dernierParagrapheDuBloc


repeat while blocDeTexte contains (space & space)

say "shorten double spaces in block " & numDuBloc

set blocDeTexte to my remplace(blocDeTexte, space & space, space)

end repeat


say "remove space from end of paragraphs in block " & numDuBloc

if blocDeTexte ends with space then set blocDeTexte to text 1 thru -2 of blocDeTexte

set blocDeTexte to my remplace(blocDeTexte, space & return, return)


say "Replace every space character by a tab in block " & numDuBloc

set blocDeTexte to my remplace(blocDeTexte, space, tab)


tell application "Numbers" to tell document myNewDoc to tell sheet 1 to tell table 1

(*

Create the first row of the new block to fill *)

repeat

try


add row below last row

exit repeat

on error

delay 0.1

end try

end repeat

(*

Define the insertion area *)

repeat

try

set selection range to range (name of cell 1 of row premierParagrapheDuBloc)

exit repeat

on error

delay 0.1

end try

end repeat

end tell


(*

Copy the datas to the clipboard *)

say "Copy the datas to the clipboard"


set the clipboard toblocDeTexte


(*

Paste in the table *)

say "paste in the table"

my raccourci("Numbers", "v", "cas")


if dernierParagrapheDuBloc < nbParagraphes then

set numDuBloc to numDuBloc + 1

set premierParagrapheDuBloc to dernierParagrapheDuBloc + 1

else

exit repeat

end if

end repeat

say "Done in " & ((current date) - debut) & " seconds."


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 recolle(l, d)

local oTIDs, t

set oTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to d

set t to l as text

set AppleScript's text item delimiters to oTIDs

return t

end recolle


--=====

(*

replaces every occurences of d1 by d2 in the text t

*)

on remplace(t, d1, d2)

local oTIDs, l

set oTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to d1

set l to text items of t

set AppleScript's text item delimiters to d2

set t to l as text

set AppleScript's text item delimiters to oTIDs

return t

end remplace


--=====

(*

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, path_to_the_App, nb_doc

if the_app is "Pages" then

tell application "Pages"

set nb_doc to count of documents


makenewdocumentwith properties {template name:item 1 of templates}

end tell

else if the_app is "Numbers" then

tell application "System Events" to the_app is in title of every application process

if not result then activateapplicationtheApp

tell application "System Events"

set path_to_the_App to get application file of application processthe_app

end tell

tell application "Numbers"

set nb_doc to count of documents

open ((path_to_the_App 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 applicationthe_app

repeat until (count of documents) > nb_doc

delay 0.1

end repeat

name of document 1

end tell -- the_App

return result

end makeAnIworkDoc


--=====


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


--=====

(*

==== 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


activateapplicationa

tell application "System Events" to tell application process a

set frontmost to true

try

t * 1

if d is "" then


key codet

else if d is "c" then


key codetusing {command down}

else if d is "a" then


key codetusing {option down}

else if d is "k" then


key codetusing {control down}

else if d is "s" then


key codetusing {shift down}

else if d is in {"ac", "ca"} then


key codetusing {command down, option down}

else if d is in {"as", "sa"} then


key codetusing {shift down, option down}

else if d is in {"sc", "cs"} then


key codetusing {command down, shift down}

else if d is in {"kc", "ck"} then


key codetusing {command down, control down}

else if d is in {"ks", "sk"} then


key codetusing {shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "k" then


key codetusing {command down, shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "a" then


key codetusing {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


keystrokekusing {option down}

else if d is "k" then


keystroke (k as text) using {control down}

else if d is "s" then


keystrokekusing {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


--=====


on run

set leFichier to choose file of type {"txt", "dat"} without invisible


run scriptmain

end run


--=====


on open sel

set leFichier to first item of sel

tell application "System Events"

try

set extension_du_nom to name extension of disk item (leFichier as text)

on error

set extension_du_nom to ""

end try

end tell

if extension_du_nom is in {"txt", "dat"} then


run scriptmain

else

set leFichier to ""

if my parleAnglais() then

error "The file" & return & leFichier & return & "isn’t a txt or dat one !"

else

error "Le fichier" & return & leFichier & return & "n’est pas de type .txt ou .dat !"

end if

end if

end open


--=====

--[/SCRIPT]

--{code}



I will post two other scripts in an other message.


Yvan KOENIG (VALLAURIS, France) jeudi 5 janvier 2012

iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

My iDisk is : http://public.me.com/koenigyvan

Please : Search for questions similar to your own before submitting them to the community


For iWork's applications dedicated to iOS, go to :

https://discussions.apple.com/community/app_store/iwork_for_ios

Jan 5, 2012 1:08 PM in response to KOENIG Yvan

Now I post two versions using do Shell Script.

The difference is huge.

I may treat the entire file in a single pass so the fact that the paste process is long doesn't matter.


The first one use the do Shell Script instruction without any other treatment.


--{code}

--[SCRIPT huge-text-to-Numbers v3]

(*

Enregistrer le script en tant qu’application : huge-text-to-Numbers.app

Il sera très bien sur le bureau.


mode 1 :

Double clic sur “huge-text-to-Numbers.app”

Un dialogue demande de naviguer vers le fichier txt ou dat à traiter

mode 2 :

Glisser déposer l'icône du fichier texte à traiter sur celle de “huge-text-to-Numbers.app”


Dans les deux cas, le script utilise une instruction UNIX (remercions Steve Majewski)

pour remplacer les groupes d'espaces par un caractère TAB.

Les données texte ainsi réorganisées sont collées dans un nouveau document Numbers.


--=====


Save the script as an Application : huge-text-to-Numbers.app

The Desktop would be a good location.


mode 1 :

Double click on “huge-text-to-Numbers.app”

A dialog allow to navigate to the txt or dat file to import.

mode 2 :

Drag and drop the text file icon on the “huge-text-to-Numbers.app” one.


In both cases the script use an UNIX instruction (thanks to Steve Majewski)

to replace chunks of spaces by single TAB character.

Then, the reorganized datas are pasted in a new Numbers document.


--=====


Yvan KOENIG (VALLAURIS, France)

2012-01-05

*)


property leFichier : ""


--=====

(*

Script object called from the run or the open handlers located at the very end

The path to the text file to treat is passed thru the property leFichier *)

script main

local debut, the_path_qUnix, edited_text, myNewDoc

my activateGUIscripting()

set debut to current date

set the_path_qUnix to quoted form of POSIX path of (leFichier as text)


(*

Instruction given by Steve Majewski *)

set edited_text to do shell script "tr -s ' ' ' ' <" & the_path_qUnix


(*

Copy the datas to the clipboard *)


set the clipboard toedited_text


(*

Create a blank Numbers spreadsheet *)

set myNewDoc to my makeAnIworkDoc("Numbers")


tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1


(*

Remove the default headers *)


removerow 1


removecolumn 1


(*

Define the insertion area *)

set selection range to range "A1"

end tell


(*

Paste matching style *)

my raccourci("Numbers", "v", "cas")

say "Done in " & ((current date) - debut) & " seconds."


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


--=====

(*

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, path_to_the_App, nb_doc, doc_name

if the_app is "Pages" then

tell application "Pages"

set nb_doc to count of documents


makenewdocumentwith properties {template name:item 1 of templates}

end tell

else if the_app is "Numbers" then

tell application "System Events" to the_app is in title of every application process

if not result then activateapplicationtheApp

tell application "System Events"

set path_to_the_App to get application file of application processthe_app

end tell

tell application "Numbers"

set nb_doc to count of documents

open ((path_to_the_App 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 applicationthe_app

repeat until (count of documents) > nb_doc

delay 0.1

end repeat

name of document 1

end tell -- the_App

return result

end makeAnIworkDoc


--=====


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


--=====

(*

==== 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


activateapplicationa

tell application "System Events" to tell application process a

set frontmost to true

try

t * 1

if d is "" then


key codet

else if d is "c" then


key codetusing {command down}

else if d is "a" then


key codetusing {option down}

else if d is "k" then


key codetusing {control down}

else if d is "s" then


key codetusing {shift down}

else if d is in {"ac", "ca"} then


key codetusing {command down, option down}

else if d is in {"as", "sa"} then


key codetusing {shift down, option down}

else if d is in {"sc", "cs"} then


key codetusing {command down, shift down}

else if d is in {"kc", "ck"} then


key codetusing {command down, control down}

else if d is in {"ks", "sk"} then


key codetusing {shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "k" then


key codetusing {command down, shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "a" then


key codetusing {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


keystrokekusing {option down}

else if d is "k" then


keystroke (k as text) using {control down}

else if d is "s" then


keystrokekusing {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


--=====


on run

set leFichier to choose file of type {"txt", "dat"} without invisible


run scriptmain

end run


--=====


on open sel

set leFichier to first item of sel

tell application "System Events"

try

set extension_du_nom to name extension of disk item (leFichier as text)

on error

set extension_du_nom to ""

end try

end tell

if extension_du_nom is in {"txt", "dat"} then


run scriptmain

else

set leFichier to ""

if my parleAnglais() then

error "The file" & return & leFichier & return & "isn’t a .txt or .dat one !"

else

error "Le fichier" & return & leFichier & return & "n’est pas de type .txt ou .dat !"

end if

end if

end open


--=====

--[/SCRIPT]

--{code}


In the other one, I added complementary treatment to get rid of the extraneous empty column.


--{code}

--[SCRIPT huge-text-to-Numbers v4]

(*

Enregistrer le script en tant qu’application : huge-text-to-Numbers.app

Il sera très bien sur le bureau.


mode 1 :

Double clic sur “huge-text-to-Numbers.app”

Un dialogue demande de naviguer vers le fichier txt ou dat à traiter

mode 2 :

Glisser déposer l'icône du fichier texte à traiter sur celle de “huge-text-to-Numbers.app”


Dans les deux cas, le script utilise une instruction UNIX (remercions Steve Majewski)

pour remplacer les groupes d'espaces par un caractère TAB.

Les données texte ainsi réorganisées sont collées dans un nouveau document Numbers.


--=====


Save the script as an Application : huge-text-to-Numbers.app

The Desktop would be a good location.


mode 1 :

Double click on “huge-text-to-Numbers.app”

A dialog allow to navigate to the txt or dat file to import.

mode 2 :

Drag and drop the text file icon on the “huge-text-to-Numbers.app” one.


In both cases the script use an UNIX instruction (thanks to Steve Majewski)

to replace chunks of spaces by single TAB character.

Then, the reorganized datas are pasted in a new Numbers document.


--=====


Yvan KOENIG (VALLAURIS, France)

2012-01-05

*)


property leFichier : ""


--=====

(*

Script object called from the run or the open handlers located at the very end

The path to the text file to treat is passed thru the property leFichier *)

script main

local debut, the_path_qUnix, edited_text, myNewDoc

my activateGUIscripting()

set debut to current date

set the_path_qUnix to quoted form of POSIX path of (leFichier as text)


(*

Instruction given by Steve Majewski *)

set edited_text to do shell script "tr -s ' ' ' ' <" & the_path_qUnix


(*

Set the paragraph separator to return *)

set edited_text to my recolle(paragraphs of edited_text, return)


(*

Remove the last character if it's a TAB *)

if edited_text ends with tab then set edited_text to text 1 thru -2 of edited_text


(*

Copy the datas to the clipboard *)


set the clipboard to my remplace(edited_text, tab & return, return)


(*

Create a blank Numbers spreadsheet *)

set myNewDoc to my makeAnIworkDoc("Numbers")


tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1


(*

Remove the default headers *)


removerow 1


removecolumn 1


(*

Define the insertion area *)

set selection range to range "A1"

end tell


(*

Paste matching style *)

my raccourci("Numbers", "v", "cas")

say "Done in " & ((current date) - debut) & " seconds."


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 recolle(l, d)

local oTIDs, t

set oTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to d

set t to l as text

set AppleScript's text item delimiters to oTIDs

return t

end recolle


--=====

(*

replaces every occurences of d1 by d2 in the text t

*)

on remplace(t, d1, d2)

local oTIDs, l

set oTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to d1

set l to text items of t

set AppleScript's text item delimiters to d2

set t to l as text

set AppleScript's text item delimiters to oTIDs

return t

end remplace


--=====

(*

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, path_to_the_App, nb_doc

if the_app is "Pages" then

tell application "Pages"

set nb_doc to count of documents


makenewdocumentwith properties {template name:item 1 of templates}

end tell

else if the_app is "Numbers" then

tell application "System Events" to the_app is in title of every application process

if not result then activateapplicationtheApp

tell application "System Events"

set path_to_the_App to get application file of application processthe_app

end tell

tell application "Numbers"

set nb_doc to count of documents

open ((path_to_the_App 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 applicationthe_app

repeat until (count of documents) > nb_doc

delay 0.1

end repeat

name of document 1

end tell -- the_App

return result

end makeAnIworkDoc


--=====


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


--=====

(*

==== 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


activateapplicationa

tell application "System Events" to tell application process a

set frontmost to true

try

t * 1

if d is "" then


key codet

else if d is "c" then


key codetusing {command down}

else if d is "a" then


key codetusing {option down}

else if d is "k" then


key codetusing {control down}

else if d is "s" then


key codetusing {shift down}

else if d is in {"ac", "ca"} then


key codetusing {command down, option down}

else if d is in {"as", "sa"} then


key codetusing {shift down, option down}

else if d is in {"sc", "cs"} then


key codetusing {command down, shift down}

else if d is in {"kc", "ck"} then


key codetusing {command down, control down}

else if d is in {"ks", "sk"} then


key codetusing {shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "k" then


key codetusing {command down, shift down, control down}

else if (d contains "c") and (d contains "s") and d contains "a" then


key codetusing {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


keystrokekusing {option down}

else if d is "k" then


keystroke (k as text) using {control down}

else if d is "s" then


keystrokekusing {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


--=====


on run

set leFichier to choose file of type {"txt", "dat"} without invisible


run scriptmain

end run


--=====


on open sel

set leFichier to first item of sel

tell application "System Events"

try

set extension_du_nom to name extension of disk item (leFichier as text)

on error

set extension_du_nom to ""

end try

end tell

if extension_du_nom is in {"txt", "dat"} then


run scriptmain

else

set leFichier to ""

if my parleAnglais() then

error "The file" & return & leFichier & return & "isn’t a .txt or .dat one !"

else

error "Le fichier" & return & leFichier & return & "n’est pas de type .txt ou .dat !"

end if

end if

end open


--=====

--[/SCRIPT]

--{code}


Yvan KOENIG (VALLAURIS, France) jeudi 5 janvier 2012

iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

Jan 10, 2012 9:00 AM in response to KOENIG Yvan

Before filing a report, I made several tests.

I wrote this script to build huge text files.


--{code}


set nbCols to 21

set nbRows to round (916035 / nbCols) rounding up --65535


set liste to {}

repeat with i from 1 to nbRows

set aList to {}

repeat with j from 1 to nbCols

set aVal to ""

repeat 10 times

set aVal to aVal & character id (j + 64)

end repeat

copy aVal & i to end of aList

end repeat

copy my recolle(aList, tab) to end of my liste

end repeat


set enTexte to my recolle(liste, return)

set cheminDuRapport to (path to desktop as text) & "" & nbRows & " rows of " & nbCols & " columns.txt"

my writeTo(cheminDuRapport, enTexte, text, false)

with timeout of 10 * 60 seconds

tell application "Numbers" to open file cheminDuRapport

end timeout


--=====


on recolle(l, d)

local oTIDs, t

set oTIDs to AppleScript's text item delimiters

set AppleScript's text item delimiters to d

set t to l as text

set AppleScript's text item delimiters to oTIDs

return t

end recolle


--=====

(*

Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861

*)

on writeTo(targetFile, theData, dataType, apendData)


-- targetFile is the path to the file you want to write


-- theData is the data you want in the file.


-- dataType is the data type of theData and it can be text, list, record etc.


-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it

try

set targetFile to targetFile as text

set openFile to open for accessfiletargetFile with write permission

if not apendData then set eof of openFile to 0


writetheDatatoopenFilestarting ateofasdataType


close accessopenFile

return true

on error

try


close accessfiletargetFile

end try

return false

end try

end writeTo


--====

--{code}


At first, I created files with 65535 rows but if the one with 13 columns was correctly imported, the one with 14 columns was truncated.

It appear that we may import such tables


65535 x 13 = 851 955 OK

65431 x 14 = 916 034 cells

61069 x 15 = 916 035 cells

57252 x 16 = 916 032 cells

53884 x 17 = 916 028 cells

50890 x 18 = 916 020 cells

48212 x 19 = 916 028 cells

45801 x 20 = 916 020 cells

43620 x 21 = 916 020 cells


At first, I thought that it was a problem of table size linked to the fact that iWork is an old product working only in 32 bits mode.

It seems that I was wrong because I get the same results when the individual strings aren’ built by

repeat 10 times

set aVal to aVal & character id (j + 64)

end repeat


but by


repeat 5 times

set aVal to aVal & character id (j + 64)

end repeat


or by


repeat 15 times

set aVal to aVal & character id (j + 64)

end repeat

So, at this time, the correct description of what is allowed in a table is :

the count of rows can't be greater than 65535,

the count of columns can't be greater than 256

the count of cells can't be greater than nbRows * INT(916035/nbRows)


Yvan KOENIG (VALLAURIS, France) mardi 10 janvier 2012

iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

Maximum number of rows and/or columns exceeded

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