Writing data from Julia to an Excel Spreadsheet

If you are ok to use the OpenDocument Spreadsheet Document format (that can be directly used in any modern version of Excel, not just LibreOffice/OpenOffice) you could use my package OdsIO, in particular:

using OdsIO
cd(@__DIR__)

fileOut   = "myspreadsheet.ods"
sheetName = "outSheet"

y = rand(9000,130)
a = rand(9000)
b = rand(9000)
# ...etc...

# Collect everything to export in a matrix (or DataFrame).. it is quicker than calling the export function 9000 times
out = Array{Any,2}(undef,9000,132) # adjust the type to your case, e.g. Array{Float64,2}
for i in 1:9000
    out[i,:] = vcat(y[i,:],a[i],b[i])
end

ods_write(fileOut,Dict((sheetName,1,1)=>out))

In the export function, the second parameter is a dictionary whose key is a tuple made of three elmements: (1) the sheet name (or number), (2) the row number and (3) the column number of where to start exporting the data (in this cas first row, first column of sheet “outSheet”), and the value is the actual object to export (it can be also a dataframe or an ordered dictionary).
You could obviously put the ods_write function within the for loop and writing the single row each time… it depends if you are more constrained by CPU time (go for the first approach) or memory (go for the second one)…

3 Likes