Saving and large files

Formats and versions

writeods chooses the format from the file name:

  • .ods, LibreOffice's usual zipped file;
  • .ots, a template;
  • .fods, flat XML: one file without zip, readable and easy to compare.

New files are written in ODF 1.4, the version LibreOffice writes, or in ODF 1.3 with version="1.3". An edited file keeps its version. Opening, editing and saving files is covered in Creating and editing files.

Zipped and flat files: .ods and .fods

A file can be saved in either form, whatever it was read from. A flat .fods is one XML file, which version control can store and compare line by line. Turning an .ods into one, and back, is the same as LibreOffice's File ▸ Save As with Flat XML ODF Spreadsheet or ODF Spreadsheet:

using OpenDocumentSpreadsheets

ods = newods("Budget")
ods["Budget"]["A1:B2"] = ["Rent" 900; "Food" 300]
writeods("budget.ods", ods; overwrite = true)

writeods("budget.fods", readods("budget.ods"); overwrite = true)        # zipped → flat
writeods("budget-again.ods", readods("budget.fods"); overwrite = true)  # flat → zipped
  • What is kept: everything the file holds that OpenDocumentSpreadsheets doesn't edit, as it was: styles, settings, document properties, Basic macros, and charts, formulas and other objects (inside the flat file). Pictures are kept inside the flat file too, as LibreOffice keeps them.
  • Links to files beside the document still point at them. (A zipped file stores them relative to the package, as ../report.pdf, and a flat one relative to its folder, as report.pdf.)
  • The version is the file's own, in both forms.
  • What a flat file has no place for is left out, as LibreOffice leaves it out: the thumbnail picture, which LibreOffice makes again, and a dialog, a custom toolbar, a digital signature or a part another program added. A warning names any of the last four, and the original file still has them.

Smaller files: display_text=false

display_text=false makes a file of numbers about half the size, and faster to write. It leaves out the text shown in each number, date, time and boolean cell, which LibreOffice and OpenDocumentSpreadsheets otherwise write beside the value. Spreadsheet programs work out the shown text from the value, so nothing is lost:

using OpenDocumentSpreadsheets

squares = (n = collect(1:1000), square = collect(1:1000) .^ 2)
writetable("squares.ods", squares; display_text = false, overwrite = true)

ods = newods("Data")
ods["Data"]["A1:B2"] = [1 2; 3 4]
writeods("small.ods", ods; display_text = false, overwrite = true)

streamods("rows.ods"; display_text = false, overwrite = true) do s
    writerow!(addsheet!(s, "rows"), (1, 2))
end

Tools that read only the shown text, rather than the value, would see such cells as empty.

Large files

  • To write a file too large to hold in memory, write its rows as they are produced, with streamods or writetable(...; streaming=true):
streamods("big.ods"; overwrite = true) do s
    sh = addsheet!(s, "data"; columns = ["n", "square"])
    for n in 1:1_000_000
        writerow!(sh, (n, n^2))
    end
end
  • To read one sheet of a large file, use readtable or readdata: they read the file only as far as that sheet.
  • To go through a large sheet row by row without loading it all, open the file with openods(path; enable_cache=false) and use eachrow: each row is read when you reach it, and not kept.