读取苹果Numbers文档的Ruby库?

4

有几个用于读取Microsoft Excel文件的Ruby开源库,例如roospreadsheet。那么苹果数字文档呢?有可用的工具吗?

1个回答

4

目前似乎还没有这样的库(还未出现?)。 现在的一个好方法是通过Applescript自动将文件转换为CSV格式,然后阅读此结果,而不是尝试直接读取Numbers文件。虽然这可能并不适合每个人的需求,但对我来说完全有效。

以下是Applescript代码:

# -------------------------------------------------------------------------------
# Command-line tool to convert an iWork '09 Numbers
# document to CSV.
#
# Parameters:
# - input: Numbers input file
# - output: CSV output file
#
# Attik System, Philippe Lang
#
# Creation date: 31 mai 2012
# Modification date: 
# -------------------------------------------------------------------------------
on run argv
    # We retreive the path of the script
    set myPath to (path to me)
    tell application "Finder" to set myFolder to folder of myPath

    # We get the command line parameters
    set input_file to item 1 of argv
    set output_file to item 2 of argv

    # We retreive the extension of the file
    set theInfo to (info for (input_file))
    set extname to name extension of (theInfo)

    # Paths
    set input_file_path to (myFolder as text) & input_file
    set output_file_path to (myFolder as text) & output_file

    if extname is equal to "numbers" then
        tell application "Numbers"
            open input_file_path
            save document 1 as "LSDocumentTypeCSV" in output_file_path
            close every window saving no
        end tell
    end if
end run

使用方法如下:

osascript convert_to_csv.scpt input_file.numbers output_file.csv

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接