2016-12-06 122 views

回答

4

如果Python是安裝在機器上,在ezodf模塊可以很直接地由朱莉婭使用,使用PyCall

using PyCall 
using DataFrames 

@pyimport ezodf 
doc = ezodf.opendoc("test.ods") 
nsheets = length(doc[:sheets]) 
println("Spreadsheet contains $nsheets sheet(s).") 
for sheet in doc[:sheets] 
    println("---------") 
    println(" Sheet name : $(sheet[:name])") 
    println("Size of Sheet : (rows=$(sheet[:nrows]()), cols=$(sheet[:ncols]()))") 
end 

# convert the first sheet to a dictionary 
sheet = doc[:sheets][1] 
df_dict = Dict() 
col_index = Dict() 
for (i, row) in enumerate(sheet[:rows]()) 
    # row is a list of cells 
    # assume the header is on the first row 
    if i == 1 
     # columns as lists in a dictionary 
     [df_dict[cell[:value]] = [] for cell in row] 
     # create index for the column headers 
     [col_index[j]=cell[:value] for (j, cell) in enumerate(row)] 
     continue 
    end 
    for (j, cell) in enumerate(row) 
     # use header instead of column index 
     append!(df_dict[col_index[j]],cell[:value]) 
    end 
end 

# and convert the dictionary to a DataFrame 
df = DataFrame(df_dict) 

(這是隻是在朱莉婭重寫davidovitch的Python代碼on this answer

編輯:

我現在根據此代碼編寫了一個Julia包裝:OdsIO

它提供了幾種從ods文件(包括單元格範圍)導入數據的功能,並希望它很快能夠導出數據。

EDIT2:

導出到ODS自版本v0.1.0

現在支持
相關問題