API reference: files, cells and tables
OpenDocumentSpreadsheets.OpenDocumentSpreadsheets — Module
OpenDocumentSpreadsheetsRead and write OpenDocument spreadsheets (.ods, .fods, .ots) in pure Julia.
The manual is at https://TimG1964.github.io/OpenDocumentSpreadsheets.jl/dev/.
Files and sheets
OpenDocumentSpreadsheets.readods — Function
readods(source) -> ODSFileRead an OpenDocument spreadsheet from a file path or an IO: openods with the cache enabled. Each sheet is parsed the first time it is used.
ods = readods("budget.ods")
sheetnames(ods) # ["Income", "Costs"]
sh = ods["Costs"] # or ods[2]
sh["B3"] # 100.0
sh["A1:C3"] # a 3×3 matrixOpenDocumentSpreadsheets.openods — Function
openods(source; mode="r", enable_cache=true) -> ODSFile
openods(f::Function, source; mode="r", enable_cache=true)Open an OpenDocument spreadsheet (.ods, .fods or .ots, detected from the content) from a file path or an IO. The do-block form passes the file to f and returns what f returns.
content.xml is read once, and the sheets are located without being parsed.
enable_cache=true: a sheet is parsed into memory the first time one of its cells is read; later reads use that copy.enable_cache=false: every read scans the sheet again, keeping nothing, and stops after the last row it needs. Use it witheachrowto stream a large sheet.
Modes:
"r": read only."rw": read and edit; save withsaveodsorwriteods. Saving patches the original file: everything OpenDocumentSpreadsheets does not edit is kept as it was."w": start a new, empty spreadsheet (with one sheet,Sheet1) that will be written tosource; an existing file there is not read.
Writing modes need enable_cache=true. With the do-block form, a file opened for writing is saved to source after f returns (not if f throws).
openods("budget.ods"; mode = "rw") do ods # saved when the block ends
ods["Costs"]["C2"] = "Paid"
end
ods = openods("budget.ods"; mode = "rw") # or saved by hand
ods["Costs"]["C3"] = "Paid"
saveods(ods)OpenDocumentSpreadsheets.newods — Function
newods(sheetname="") -> ODSFileA new, empty spreadsheet with one sheet (Sheet1, or sheetname), open for writing. Write it with writeods.
ods = newods("Results")
sh = ods["Results"]
sh["A1:B1"] = ["Item" "Total"]
sh["A2"] = "Paper"; sh["B2"] = 12.5
writeods("results.ods", ods; overwrite = true)OpenDocumentSpreadsheets.writeods — Function
writeods(dest, ods::ODSFile; overwrite=false, version="1.4") -> path or nothingWrite ods to dest, a file path or an IO.
- The format follows the extension of a path:
.ods,.ots(a template) or.fods(flat XML). Writing to anIOkeeps the format the file was read in (.odsfor a new one). - A file that was read is written by patching it: what OpenDocumentSpreadsheets does not edit is kept exactly as it was. It can be written as a template or a document, and zipped or flat: an
.odssaved as.fodsis one XML document, with its pictures and charts inside it, as LibreOffice's Save As ▸ Flat XML ODF Spreadsheet writes it, and a.fodscan be saved as.odsagain. Its links to files beside it still point at them. What a flat file has no place for is left out, as LibreOffice leaves it out: the thumbnail, and a dialog, a toolbar, a signature or a part another program added, which a warning names. - A new file is written in ODF 1.4, or 1.3 with
version="1.3". display_text=falseleaves out the display text (text:p) of the number, date, time and boolean cells that OpenDocumentSpreadsheets writes; readers recompute it from the value. Files are then smaller (about half, for numeric data) and faster to write.- An existing file at
destis only replaced withoverwrite=true.
A path becomes the file's new source (for saveods). Returns the absolute path, or nothing for an IO.
ods = openods("budget.ods"; mode = "rw")
ods["Income"]["D1"] = "Checked"
writeods("budget-checked.ods", ods) # a copy: budget.ods is unchanged
writeods("budget.fods", ods) # flat XML, to keep in version control
writeods("template.ots", newods("Sheet1"); overwrite = true) # a templateOpenDocumentSpreadsheets.saveods — Function
saveods(ods::ODSFile)Save ods back to where it was opened from: its file, or the IO it was read from (which must be writable and seekable; its content is replaced). A file made with newods has nowhere to go: use writeods.
OpenDocumentSpreadsheets.ODSFile — Type
ODSFileAn opened spreadsheet, as openods and readods return it. Index it by sheet name or number (ods["Sheet1"], ods[1]), or with a sheet-qualified reference or a defined name (ods["Sheet1.A1:B2"], ods["Sheet1!A1"], ods["myrange"]).
OpenDocumentSpreadsheets.Worksheet — Type
WorksheetA sheet of an ODSFile. Index it like a matrix of values (sheet["A1"], sheet["A1:B3"], sheet[2, 1], sheet[:]); see getdata.
OpenDocumentSpreadsheets.sheetnames — Function
sheetnames(ods::ODSFile) -> Vector{String}The names of the sheets, in order.
OpenDocumentSpreadsheets.sheetcount — Function
sheetcount(ods::ODSFile) -> IntThe number of sheets.
OpenDocumentSpreadsheets.hassheet — Function
hassheet(ods::ODSFile, sheetname) -> BoolWhether the file has a sheet named sheetname. Names match without regard to case, as in LibreOffice, which does not allow two sheets whose names differ only in case.
OpenDocumentSpreadsheets.addsheet! — Function
addsheet!(ods::ODSFile, name="") -> WorksheetAdd an empty sheet at the end. Without a name, it is called SheetN (the first free N).
ods = newods("Income")
costs = addsheet!(ods, "Costs")
costs["A1"] = "Month"
sheetnames(ods) # ["Income", "Costs"]addsheet!(s::StreamWriter, name=""; columns=nothing, column_widths=nothing, column_formats=nothing,
as_table=false, table_name="", table_style=nothing) -> StreamSheet
addsheet!(s::StreamWriter, name, table; column_widths, column_formats, as_table, table_name, table_style) -> StreamSheetStart the next sheet of a streamed file, finishing the one before. columns writes a header row; a Tables.jl table writes its header and all its rows. column_widths and column_formats set the columns' widths and the number formats of the rows written after the header, as in writetable!. as_table=true makes the sheet's rows a table, named table_name ("": the first free TableN), as writetable! does; it needs columns.
OpenDocumentSpreadsheets.ODSError — Type
ODSErrorThe exception OpenDocumentSpreadsheets throws for its own errors: an invalid reference, a missing sheet, a file that is not an OpenDocument spreadsheet, and so on. e isa ODSError tells these apart from other errors, and e.msg is the message.
Reading cells
OpenDocumentSpreadsheets.getdata — Function
getdata(sheet, ref)
getdata(sheet, row, column)
getdata(sheet)Values from a worksheet: a scalar for a single cell, a Matrix{Any} for a rectangular range, or a vector of matrices for a list of ranges. Empty cells, empty strings and errors read as missing.
ref is a cell or range ("A1", "A1:C4", "A:B", "1:4", "A1:A4,C1"), one with its sheet named ("Sheet1.A1:C4"; "Sheet1!A1:C4" also works), or a named range. Rows and columns can also be integers, unit ranges, step ranges, vectors or :. For whole columns or rows, the other extent is the sheet's get_dimension.
Indexing a Worksheet calls getdata: sheet["A1"], sheet[1:3, 2], sheet[:].
The value types are described in Cell: Int64 or Float64 for numbers, String, Bool, Date or DateTime, and Time (or a CompoundPeriod for 24 hours or more).
OpenDocumentSpreadsheets.readdata — Function
readdata(source, sheet, ref)
readdata(source, sheetref)Open source (a path or an IO) without the cache, and return getdata of ref on sheet (a name or a number), or of a sheet-qualified reference such as "Sheet1.A1:B3" ("Sheet1!A1:B3" also works).
readdata("budget.ods", "Costs", "B2:B4") # a 3×1 matrix: 50.0, 100.0, 150.0
readdata("budget.ods", "Costs.B2") # 50.0OpenDocumentSpreadsheets.getcell — Function
getcell(sheet, ref)
getcell(sheet, row, col)The Cell at ref, or an EmptyCell where the sheet holds nothing. For a range, a Matrix{AbstractCell} (see getcellrange); ref takes the same forms as in getdata.
OpenDocumentSpreadsheets.getcellrange — Function
getcellrange(sheet, rng)The cells of a range as a Matrix{AbstractCell}, or a vector of matrices for a list of ranges. rng takes the forms of getdata.
OpenDocumentSpreadsheets.get_dimension — Function
get_dimension(ws::Worksheet; allow_load=true) -> CellRangeThe smallest range holding every cell with a value or formula. ODS files do not record it, so it is computed from the sheet (the cache, or a scan without the cache). An empty sheet gives A1:A1 (shown as empty when the sheet or its file is displayed). With allow_load=false, an unread sheet gives A1:A1 without being read.
OpenDocumentSpreadsheets.Cell — Type
CellA cell read from a worksheet. Fields:
ref::CellRef: its positiondatatype::Symbol: the ODF value type::float,:percentage,:currency,:date,:time,:boolean,:string,:error, or:empty(a formula with no result, or a covered cell)value: its value, asgetdatareturns itformula: the stored formula ("of:=[.A1]*3"), ornothing;getFormulagives it in LibreOffice's notationstyle::String: the name of its effective cell stylecurrency: the currency code of a currency cell ("GBP"), elsenothingerror: the displayed text of an error result ("#DIV/0!","Err:502"), elsenothingcolspan,rowspan: the size of a merge whose top-left cell this is (1 otherwise)covered::Bool: whether the cell is hidden by a merge
OpenDocumentSpreadsheets.EmptyCell — Type
EmptyCell(ref)A position where the worksheet holds no value and no formula.
OpenDocumentSpreadsheets.iserror — Function
iserror(sheet, ref)
iserror(sheet, row, col)Whether a cell holds an error result (#DIV/0!, #N/A, Err:502, ...), which getdata reads as missing. For a range, a matrix of Bools (a vector of them for a list of ranges). The ODF file marks errors with calcext:value-type="error".
iserror(r::ChartRef) -> Vector{Bool}
iserror(r::ChartRef, i) -> Bool
geterror(r::ChartRef) -> Vector{String}
geterror(r::ChartRef, i) -> StringWhether each value of a chart reference is an error, and its error text ("" where none). Every error kind is reported, since the values come from the cells.
OpenDocumentSpreadsheets.geterror — Function
geterror(sheet, ref)
geterror(sheet, row, col)The displayed text of an error result, such as "#DIV/0!" or "Err:502", or "" for a cell without one. For a range, a matrix of strings.
OpenDocumentSpreadsheets.getFormula — Function
getFormula(sheet, ref; raw=false) -> Union{String, Nothing}
getFormula(sheet, row, col; raw=false)
getFormula(ods, "Sheet1.A1"; raw=false)The formula of a cell, as LibreOffice shows it ("=SUM(A1:B2,1)", "='My sheet'.A1*2"), or nothing if the cell has none. With raw=true, the formula as stored in the file ("of:=SUM([.A1:.B2];1)").
The UI notation follows LibreOffice with its en-US settings: , between function arguments and between the columns of an inline array, ; between its rows. Formulas written in another namespace than OpenFormula (such as msoxl:) lose their prefix and are otherwise returned unchanged.
Every cell of an array formula gives the formula in braces, as LibreOffice's formula bar shows it: "{=A1:A3*2}" (getArrayFormulas). With raw=true, only the first cell of its range has one, as it is stored.
OpenDocumentSpreadsheets.getArrayFormulas — Function
getArrayFormulas(sheet) -> Vector{CellRange}The areas of the sheet's array formulas, in order of their first cells: each is the range that LibreOffice fills with the formula's results. getFormula on any of its cells gives the formula in braces ("{=A1:A3*2}").
setFormula(sh, "E1:E3"; val = "=A1:A3*2", array = true)
OpenDocumentSpreadsheets.getArrayFormulas(sh) # [E1:E3]OpenDocumentSpreadsheets.getRichTextString — Function
getRichTextString(sheet, ref) -> Union{RichTextString, Nothing}
getRichTextString(sheet, row, col) -> Union{RichTextString, Nothing}
getRichTextString(ods, "Sheet1!A1") -> Union{RichTextString, Nothing}A text cell's rich text: its runs and their attributes, or nothing for a cell whose text has no runs of its own formatting (plain text, a number, an empty cell). It reads the cells written with a RichTextString and rich text made in LibreOffice (its spans' text styles), while their text is unchanged. A run's attributes are those its span sets: the rest are the cell's.
OpenDocumentSpreadsheets.RichTextString — Type
RichTextString(runs::RichTextRun...) -> RichTextString
RichTextString(runs::Vector{RichTextRun}) -> RichTextStringA cell's text made of runs, each with its own font attributes (see RichTextRun). Its text is the runs' joined; a "\n" starts a new line (a paragraph in ODF).
Written to a cell (sheet["A1"] = rt), each run with attributes is a span with a text style, as LibreOffice keeps one. A string of one run is written as plain text, the run's attributes the cell's font (setFont), but a superscript or subscript, which a cell style can't hold. getRichTextString reads one back.
OpenDocumentSpreadsheets.RichTextRun — Type
RichTextRun(text::AbstractString, pairs::Union{Nothing,Vector{Pair{Symbol,Any}}} = nothing) -> RichTextRunOne run of a RichTextString: its text and none, one or several font attributes:
:bold,:italic,:under,:strike:trueto set it;:vertAlign:"superscript"or"subscript";:color: a colour, as hex ("FF0000","FFFF0000") or a name ("red");:size: the font size in points;:name: the font's name.
An attribute a run doesn't set is the cell's, as in LibreOffice.
rt = RichTextString(RichTextRun("Water is H"), RichTextRun("2", [:vertAlign => "subscript"]),
RichTextRun("O!", [:bold => true]))
sh["A1"] = rtOpenDocumentSpreadsheets.SheetRow — Type
SheetRowA row of a worksheet, as eachrow gives it. row_number(r) is its number; r[col] (a column number or name such as "B") is a value, getcell(r, col) a cell.
Base.eachrow — Method
eachrow(sheet::Worksheet)Iterate the rows of sheet that have content, as SheetRows, in order. Repeated rows are given one by one. With the cache on, the sheet is read into the cache first; with enable_cache=false (openods), rows are read as they are iterated.
for r in eachrow(ods["Sheet1"])
println(row_number(r), ": ", r[1], ", ", r["B"])
endOpenDocumentSpreadsheets.column_number — Function
OpenDocumentSpreadsheets.CellRef — Type
CellRef(ref::AbstractString)
CellRef(row, column)A cell's position on a sheet, without the sheet: CellRef("B6") is column 2, row 6, and so is CellRef(6, 2). row_number and column_number give its row and column, and string its name. Anywhere a cell is given as a string ("B6"), a CellRef can be given instead.
c = CellRef("AB1")
row_number(c) # 1
column_number(c) # 28
string(CellRef(1, 28)) # "AB1"SheetCellRef names the sheet too.
OpenDocumentSpreadsheets.SheetCellRef — Type
SheetCellRef(ref::AbstractString)
SheetCellRef(sheet::AbstractString, cellref::CellRef)A cell on a named sheet, written as LibreOffice's Name Box shows it: SheetCellRef("Sheet1.B2"), or SheetCellRef("'My sheet'.B2") for a sheet whose name needs quotes. Its fields are sheet, the sheet's name, and cellref, a CellRef. It prints in the same form. Parsing also accepts $ marks ("$Sheet1.$B$2") and the form other spreadsheet programs use ("Sheet1!B2").
r = SheetCellRef("'My sheet'.B2")
r.sheet # "My sheet"
r.cellref # B2
SheetCellRef("Data", CellRef("A1")) # Data.A1Tables
OpenDocumentSpreadsheets.readtable — Function
readtable(source, [sheet, [columns]]; [table_name], [first_row], [column_labels], [header],
[infer_eltypes], [stop_in_empty_row], [stop_in_row_function],
[keep_empty_rows], [normalizenames], [missing_strings]) -> DataTableRead a table, a block of rows under a header row, from a file path or IO: the table on sheet (a name or number; the first sheet if not given), as gettable reads it. The sheet is read row by row and not kept in memory.
using DataFrames
df = DataFrame(readtable("budget.ods", "Income"))
readtable("budget.ods", "Income", "A:B") # only columns A and BUse first_row to give the first row of the table (its header, if header=true). Without it, the table starts at the first row with data in its first column.
header (default true) says whether the first row holds the column labels. Without a header, and without column_labels, the labels are the column letters.
column_labels gives the labels as a vector of Symbols or strings.
normalizenames=true turns the labels into valid Julia identifiers.
missing_strings gives strings (one, or a vector) to read as missing.
infer_eltypes (default true) gives each column the narrowest element type of its values; otherwise columns are Vector{Any}.
stop_in_empty_row (default true) ends the table at the first empty row. stop_in_row_function is a function of a TableRow returning true at the row that ends the table (that row is left out).
keep_empty_rows (default false) keeps rows whose values are all missing between the first and the last row of the table.
table_name reads a database range (see table) instead: its data rows, without its header and totals rows, as gettable reads a Table, from sheet or, if none is given, from the whole file. The range's cells are its own, so columns, first_row, header, column_labels, stop_in_empty_row, stop_in_row_function and keep_empty_rows don't apply (columns with table_name is an error).
An enable_cache keyword is accepted, and has no effect.
OpenDocumentSpreadsheets.gettable — Function
gettable(sheet, [columns]; [first_row], [column_labels], [header], [infer_eltypes],
[stop_in_empty_row], [stop_in_row_function], [keep_empty_rows],
[normalizenames], [missing_strings]) -> DataTableThe table in sheet as a DataTable, which any Tables.jl sink accepts (DataFrame(gettable(sheet))). columns selects the columns ("B:D"); without it, the table's columns are found as in eachtablerow.
Use first_row to give the first row of the table (its header, if header=true). Without it, the table starts at the first row with data in its first column.
header (default true) says whether the first row holds the column labels. Without a header, and without column_labels, the labels are the column letters.
column_labels gives the labels as a vector of Symbols or strings.
normalizenames=true turns the labels into valid Julia identifiers.
missing_strings gives strings (one, or a vector) to read as missing.
infer_eltypes (default true) gives each column the narrowest element type of its values; otherwise columns are Vector{Any}.
stop_in_empty_row (default true) ends the table at the first empty row. stop_in_row_function is a function of a TableRow returning true at the row that ends the table (that row is left out).
keep_empty_rows (default false) keeps rows whose values are all missing between the first and the last row of the table.
gettable(t::Table; infer_eltypes=true, normalizenames=false, missing_strings=nothing) -> DataTableA table's data rows (without its header and totals rows) as a DataTable, labelled by its columns: its range is the table's, so empty rows inside it are data. normalizenames, missing_strings and infer_eltypes are as for gettable(sheet).
OpenDocumentSpreadsheets.eachtablerow — Function
eachtablerow(sheet, [columns]; [first_row], [column_labels], [header],
[stop_in_empty_row], [stop_in_row_function], [keep_empty_rows],
[normalizenames], [missing_strings]) -> TableRowIteratorAn iterator of the rows of the table in sheet, each a TableRow (index it with a column number or label: r[1], r[:name]). columns is a column range such as "B:E"; without it, the columns are the first run of consecutive non-empty cells in the table's first row.
Use first_row to give the first row of the table (its header, if header=true). Without it, the table starts at the first row with data in its first column.
header (default true) says whether the first row holds the column labels. Without a header, and without column_labels, the labels are the column letters.
column_labels gives the labels as a vector of Symbols or strings.
normalizenames=true turns the labels into valid Julia identifiers.
missing_strings gives strings (one, or a vector) to read as missing.
infer_eltypes (default true) gives each column the narrowest element type of its values; otherwise columns are Vector{Any}.
stop_in_empty_row (default true) ends the table at the first empty row. stop_in_row_function is a function of a TableRow returning true at the row that ends the table (that row is left out).
keep_empty_rows (default false) keeps rows whose values are all missing between the first and the last row of the table.
OpenDocumentSpreadsheets.readto — Function
readto(source, [sheet, [columns]], sink; kw...)Read a table with readtable and pass it to the Tables.jl sink, such as DataFrame: readto("budget.ods", "Income", DataFrame).
OpenDocumentSpreadsheets.DataTable — Type
DataTableA table read from a sheet, as readtable and gettable return it: its columns and their labels. Any Tables.jl sink accepts it, such as DataFrame(dt).
OpenDocumentSpreadsheets.TableRow — Type
TableRowA row of a table, as eachtablerow gives it. Index it with a column number or label: r[1], r[:Amount]. row_number(r) is its position in the table (1 for the first row under the header), not its row on the sheet.
OpenDocumentSpreadsheets.TableRowIterator — Type
TableRowIteratorWhat eachtablerow returns: an iterator of TableRows, which is also a Tables.jl table. gettable(itr) reads all its rows into a DataTable.
Writing
OpenDocumentSpreadsheets.setdata! — Function
setdata!(sheet, ref, value)
setdata!(sheet, row, col, value)
sheet[ref] = value
sheet[row, col] = valueWrite value into a cell, or into every cell of a range. The file must be writable (openods with mode="rw" or "w", or newods).
valuemay be a number, string,Bool,Date,DateTime,Time, a period (a duration), ormissing/nothingto empty the cell.- A matrix fills a range of its size.
- A vector fills a row (
dim=2, the default) or a column (dim=1) from a cell, or a one-row or one-column range. reftakes the forms ofgetdata:"B2","B2:D4","Sheet1.B2","Sheet1!B2", integers and ranges, or a defined name that refers to cells on the sheet.- With
:for the rows or columns:ws[3, :] = [1, 2, 3]writes a vector along row 3 from column A, andws[:, 2] = vdown column B from row 1. Any other value fills the cells addressed, where:stands for the sheet's used columns or rows (ws[3, :] = 0,ws[:, 2:3] = missing,ws[:] = 1).
A cell keeps its style when that style's format fits the new value. Otherwise dates, date-times, times and booleans get ISO formats, and numbers and text the Default style.
OpenDocumentSpreadsheets.setFormula — Function
setFormula(sheet, ref; val, raw=false, array=false)
setFormula(sheet, row, col; val, raw=false, array=false)Write a formula into a cell, or into every cell of a range (the same formula in each). val is in LibreOffice's notation, as getFormula gives it: "=SUM(B1:B3,'My sheet'.A1)". It is stored as OpenFormula (of:=SUM([.B1:.B3];['My sheet'.A1])). With raw=true, val is stored as given, and must be a stored formula such as "of:=[.A1]*2".
With array=true, the formula is one array formula over the whole range, as LibreOffice's Ctrl+Shift+Enter enters it over a selection: LibreOffice fills the range with its results, for example the values of "=UNIQUE(A2:A20)" or "=A2:A9*B2:B9". The range must be the size of the results: in a larger one LibreOffice shows #N/A in the cells left over, and a smaller one shows only part of them. A range of one cell holds an array formula with one result, such as "=SUM(A2:A9*B2:B9)". The cells of an array formula can only be changed together: writing to part of one is an error, and writing over all of it replaces it. See getArrayFormulas.
The cells' values are left empty: LibreOffice computes them when it opens the file.
setFormula(sh, "D1"; val = "=SUM(A1:A4)")
setFormula(sh, "D2:D4"; val = "=A2*2") # the same formula in each cell
setFormula(sh, "E2:E4"; val = "=A2:A4*B2:B4", array = true) # one formula, three resultssetFormula(ods::ODSFile, "Sheet1.A1", args...; kw...)The same, on a cell or range given with its sheet.
OpenDocumentSpreadsheets.writetable — Function
writetable(filename, data, columnnames; overwrite=false, sheetname="", anchor_cell="A1", streaming=false, kw...)
writetable(filename, table; overwrite=false, sheetname="", anchor_cell="A1", streaming=false, kw...)
writetable(filename, "Sheet1" => table1, "Sheet2" => table2, ...; overwrite=false, streaming=false, kw...)
writetable(filename, [(sheetname, data, columnnames), ...]; overwrite=false, streaming=false, kw...)
writetable(filename; overwrite=false, streaming=false, Sheet1=(data, columnnames), ...)Write tables to a new file (a path or an IO), one per sheet, each with a header row. The format follows the file's extension (.ods, .ots, .fods). An existing file is only replaced with overwrite=true. With streaming=true, rows are written as they are produced, in bounded memory (streamods); anchor_cell, totals and freeze_header are then not available. display_text=false leaves out the display text of number, date, time and boolean cells (smaller files, faster writes; see writeods). column_widths and column_formats lay out every sheet's columns, as in writetable!.
as_table=true makes each written range a table, as writetable! does (also streamed). A single table is named table_name, with its totals; with several sheets, each table is named after its sheet (made a valid name, with a warning, or the first free TableN).
sales = (Region = ["North", "South"], Total = [120, 95])
writetable("sales.ods", sales; sheetname = "Sales", overwrite = true)
writetable("report.ods", "Sales" => sales, "Costs" => (Item = ["Rent"], Amount = [800]);
overwrite = true) # one sheet per tableOpenDocumentSpreadsheets.writetable! — Function
writetable!(sheet, data, columnnames; anchor_cell="A1", write_columnnames=true, column_widths,
column_formats, as_table=false, table_name="", table_style=nothing, totals=nothing,
freeze_header=false)
writetable!(sheet, table; kw...)Write a table into sheet, with its column names as a header row (unless write_columnnames=false) and its top-left cell at anchor_cell. data is a vector of columns and columnnames their names; or table is any Tables.jl table.
column_widths: one width for every column, or a vector of widths by column (nothingleaves a column's width as it is), in characters assetColumnWidthtakes them.column_formats: aDictfrom column (number from the first written, or name) to a number format, assetFormattakes it, applied to the column's data cells.as_table=truemakes the written cells a table (addtable!: LibreOffice's database range), namedtable_name("": the first freeTableN). It needs the header row. LibreOffice has no table styles, sotable_styleother thannothingor"None"is an error.totals(withas_table) gives the table a totals row, assettotals!does:["id" => "Total", "score" => :sum].freeze_header=truefreezes the rows down to the header (freezePanes).
OpenDocumentSpreadsheets.streamods — Function
streamods(f, dest; overwrite=false, version="1.4", display_text=true, declare_widths=[])Write a new file to dest (a path or an IO) row by row, in bounded memory. f gets a StreamWriter: add sheets with addsheet!(s, name; columns) (a header row) or addsheet!(s, name, table) (a Tables.jl table, header and rows), and write rows with writerow! and writerows!. The format follows the extension (.ods, .ots; flat .fods is not streamed). display_text=false leaves out the display text of number, date, time and boolean cells, as in writeods.
Column widths (addsheet!(…; column_widths)) are declared at the start of the file, before its first sheet: a width a later sheet uses must be the first sheet's too, or be listed in declare_widths (in characters). writetable(…; streaming=true) declares them all.
streamods("big.ods") do s
sh = addsheet!(s, "data"; columns = ["n", "square"])
for n in 1:1_000_000
writerow!(sh, (n, n^2))
end
endOpenDocumentSpreadsheets.StreamWriter — Type
StreamWriterA file being written by streamods. Add sheets to it with addsheet!.
OpenDocumentSpreadsheets.StreamSheet — Type
StreamSheetA sheet being written by streamods. Write rows to it in order with writerow! and writerows!.
OpenDocumentSpreadsheets.writerow! — Function
writerow!(sh::StreamSheet, row)Write the next row of a streamed sheet: a tuple, NamedTuple or vector of values (missing or nothing leave a cell empty).
OpenDocumentSpreadsheets.writerows! — Function
writerows!(sh::StreamSheet, table)Write every row of a Tables.jl table (without its header) to a streamed sheet.