Read and Write Excel Files
The Taro.readxl
function is a simple, high level method to read tabular data from Excel files into a Julia DataFrames. For more control over reading files cell by cell, and for creating or modifyting excel files, this package exposes functions to read, create and write workbooks, sheets, rows and cells. The functions are modelled on the underlying POI API (converted to functional form), which in turn is based on the structure of an Excel file.
t=now()
w=Workbook()
s=createSheet(w, "runtests")
r=createRow(s, 1)
c=createCell(r, 1); setCellValue(c, "A String")
c=createCell(r, 2); setCellValue(c, 25)
c=createCell(r, 3); setCellValue(c, 2.5)
c=createCell(r, 4); setCellValue(c, t)
s=createCellStyle(w)
setDataFormat(w, s, "m/d/yy h:mm")
setCellStyle(c, s)
c=createCell(r, 5); setCellFormula(c, "C2+D2")
write(Pkg.dir("Taro", "test", "write-tests.xlsx"), w)
We can now read the file we just wrote, and verify the values we inserted.
julia> w2=Workbook(Pkg.dir("Taro", "test", "write-tests.xlsx"))
JavaCall.JavaObject{symbol("org.apache.poi.ss.usermodel.Workbook")}(Ptr{Void} @0x00007fe76bbe65c0)
julia> s2 = getSheet(w2, "runtests")
JavaCall.JavaObject{symbol("org.apache.poi.ss.usermodel.Sheet")}(Ptr{Void} @0x00007fe76bbe65b0)
julia> r2 = getRow(s2, 1)
JavaCall.JavaObject{symbol("org.apache.poi.ss.usermodel.Row")}(Ptr{Void} @0x00007fe76bbe6498)
julia> c2 = getCell(r2, 1); getCellValue(c2)
"A String"
julia> c2 = getCell(r2, 2); getCellValue(c2)
25.0
julia> c2 = getCell(r2, 3); getCellValue(c2)
2.5
julia> c2 = getCell(r2, 4); getCellValue(c2)
2016-06-14T22:47:38
julia> c2 = getCell(r2, 5); getCellFormula(c2)
"C2+D2"