Apple Script to copy .numbers file
I am trying to write an apple script that will read a numbers file on my computer and copy its data onto a new numbers file cell by cell. So far I have it working where the cell value and color is correctly copied over, but for some reason the formulas do not display properly.
They all say "The formula contains a syntax error" despite the formulas all visually looking correct when I inspect them.
Can anyone help resolve this issue and make the formulas actually calculate the value? My code is below.
-- Specify the file paths
set sourceFile to "/users/colepropach/Desktop/app/test.numbers"
-- Open Numbers application
tell application "Numbers"
activate
set newDocument to make new document
-- address the document reference
tell newDocument
-- remove any default tables
delete every table of every sheet
end tell
-- Open the source file
open sourceFile
-- Get the document
tell the front document
repeat with sheetIndex from 1 to count sheets
set currentSheet to sheet sheetIndex
tell newDocument
set newSheet to make new sheet
delete every table of newSheet
end tell
-- Get tables in the current sheet
repeat with tableIndex from 1 to count tables of currentSheet
set currentTable to table tableIndex of currentSheet
set rowCount to row count of currentTable
set columnCount to column count of currentTable
tell newDocument
tell newSheet
set newTable to make new table with properties {row count:rowCount, column count:columnCount}
end tell
end tell
-- Get rows in the current table
repeat with rowIndex from 1 to count rows of currentTable
set currentRow to row rowIndex of currentTable
-- Get cells in the current row
repeat with cellIndex from 1 to count cells of currentRow
set currentCell to cell cellIndex of currentRow
set cellValue to value of currentCell
set cellFormula to formula of currentCell
set cellColor to background color of currentCell
tell newDocument
tell newSheet
tell newTable
if cellFormula is not missing value then
set value of cell cellIndex of row rowIndex to cellFormula
else if cellValue is not missing value then
set value of cell cellIndex of row rowIndex to cellValue
end if
if cellColor is not missing value then
set background color of cell cellIndex of row rowIndex to cellColor
end if
end tell
end tell
end tell
end repeat
end repeat
end repeat
end repeat
-- close saving no
end tell
-- quit saving no
end tell