本文介绍了用于读取 Apple Numbers 文档的 Ruby 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几个用于读取 Microsoft Excel 文件的 Ruby 开源库,例如 roo电子表格.Apple Numbers 文件呢?有什么可用的吗?

There are several Ruby open-source libraries for reading Microsoft Excel files, such as roo or spreadsheet. What about Apple Numbers documents? Is there anything available?

推荐答案

这样的库显然不存在(还没有?).现在一个好的解决方法是通过applescript自动转换为CSV,然后读取这个结果而不是尝试直接读取Numbers文件.不过,这可能不适合每个人的需求,但对我来说非常适合.

Such a library apparently does not exist (yet?). A good workaround for now is to automate the conversion to CSV through applescript, and then read this result instead of trying to read the Numbers file directly. This might not fit everyone's needs, though, but works perfectly for me.

这是苹果的脚本:

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

这篇关于用于读取 Apple Numbers 文档的 Ruby 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 12:33