ddn.odf.document

Core ODF document types and the main OdfDocument class.

This module defines the central document abstraction for reading and writing OpenDocument files.

Supported document types

All ODF document families are supported: text (ODT), spreadsheet (ODS), drawing (ODG), presentation (ODP), chart (ODC), formula (ODF), image (ODI), and database (ODB). Template variants and flat XML formats are also supported.

Examples

Open an existing document

--- import ddn.odf.document;

auto doc = openOdfDocument("report.odt"); ---

Create a new document

--- import ddn.odf.document;

auto doc = createOdfDocument(OdfDocumentType.TEXT); ---

Types 10

Enumeration of OpenDocument document types.

All document families have full read/write support including typed editing, round-trip preservation, and creation APIs.

Template, master-document, and flat XML variants are separate entries because they have distinct MIME types and package structures.

NONE = 0
TEXT = 1
TEXT_TEMPLATE = 2
TEXT_MASTER = 3
TEXT_WEB = 4
SPREADSHEET = 5
SPREADSHEET_TEMPLATE = 6
PRESENTATION = 7
PRESENTATION_TEMPLATE = 8
DRAWING = 9
DRAWING_TEMPLATE = 10
CHART = 11
FORMULA = 12
IMAGE = 13
DATABASE = 14

Represents an opened ODT text document with typed access to body, styles, metadata, and settings.

Use openOdfTextDocument to create instances from .odt files.

Fields
private string _mimeType
private OdfTextBody _body
private OdfStyles _styles
private OdfMetadata _metadata
private OdfSettings _settings
private OdfContent _content
private ManifestModel _manifest
private OdfDocumentType _docType
Methods
string mimeType() @property const @safe pure nothrow @nogcReturns the MIME type of this document.
OdfDocumentType documentType() @property const @safe pure nothrow @nogcReturns the document type (TEXT, TEXT_TEMPLATE, TEXT_MASTER, or TEXT_WEB).
const(OdfTextBody) body() @property ref const @safe pure nothrow @nogcReturns the parsed text body.
const(OdfStyles) styles() @property ref const @safe pure nothrow @nogcReturns the parsed document styles.
const(OdfMetadata) metadata() @property ref const @safe pure nothrow @nogcReturns the parsed document metadata.
const(OdfSettings) settings() @property ref const @safe pure nothrow @nogcReturns the parsed document settings.
const(OdfContent) content() @property ref const @safe pure nothrow @nogcReturns the parsed content model.
string plainText() @safe pure nothrow constExtracts the plain text content from the document body.
void save(string path)Saves this text document to the given file path.
void setMimeType(string mt) @safe pure nothrow
void setBody(OdfTextBody body) @safe pure nothrow
void setStyles(OdfStyles styles) @safe pure nothrow
void setMetadata(OdfMetadata metadata) @safe pure nothrow
void setSettings(OdfSettings settings) @safe pure nothrow
void setContent(OdfContent content) @safe pure nothrow
void setDocumentType(OdfDocumentType dt) @safe pure nothrow

Represents an OpenDocument file.

An OdfDocument wraps the ZIP container and provides access to the embedded XML streams (content, styles, metadata, manifest).

Fields
private string _mimeType
private OdfDocumentType _docType
Methods
string mimeType() @property const @safe pure nothrow @nogcReturns the MIME type of this document.
OdfDocumentType documentType() @property const @safe pure nothrow @nogcReturns the document type.
void save(string path)Saves the document to the given file path.
void setMimeType(string mt) @safe pure nothrow
void setDocumentType(OdfDocumentType dt) @safe pure nothrow

Represents an opened ODS spreadsheet document with typed access to sheets, styles, metadata, and settings.

Use openOdfSpreadsheetDocument to create instances from .ods files.

Fields
private string _mimeType
private OdfSpreadsheetBody _body
private OdfStyles _styles
private OdfMetadata _metadata
private OdfSettings _settings
private OdfDocumentType _docType
Methods
string mimeType() @property const @safe pure nothrow @nogcReturns the MIME type.
OdfDocumentType documentType() @property const @safe pure nothrow @nogcReturns the document type (SPREADSHEET or SPREADSHEET_TEMPLATE).
const(OdfSpreadsheetBody) body() @property ref const @safe pure nothrow @nogcReturns the parsed spreadsheet body.
const(OdfStyles) styles() @property ref const @safe pure nothrow @nogcReturns the parsed styles.
const(OdfMetadata) metadata() @property ref const @safe pure nothrow @nogcReturns the parsed metadata.
const(OdfSettings) settings() @property ref const @safe pure nothrow @nogcReturns the parsed document settings.
size_t sheetCount() const @safe pure nothrowReturns the number of sheets.
void save(string path)Saves this spreadsheet document to the given file path.
void setMimeType(string mt) @safe pure nothrow
void setBody(OdfSpreadsheetBody body) @safe pure nothrow
void setStyles(OdfStyles styles) @safe pure nothrow
void setMetadata(OdfMetadata metadata) @safe pure nothrow
void setSettings(OdfSettings settings) @safe pure nothrow
void setDocumentType(OdfDocumentType dt) @safe pure nothrow

Represents an opened ODG drawing document with typed access to pages, shapes, styles, metadata, and settings.

Use openOdfDrawingDocument to create instances from .odg files.

Fields
private string _mimeType
private OdfDrawingBody _body
private OdfStyles _styles
private OdfMetadata _metadata
private OdfSettings _settings
private OdfDocumentType _docType
Methods
string mimeType() @property const @safe pure nothrow @nogcReturns the MIME type.
OdfDocumentType documentType() @property const @safe pure nothrow @nogcReturns the document type (DRAWING or DRAWING_TEMPLATE).
const(OdfDrawingBody) body() @property ref const @safe pure nothrow @nogcReturns the parsed drawing body.
const(OdfStyles) styles() @property ref const @safe pure nothrow @nogcReturns the parsed styles.
const(OdfMetadata) metadata() @property ref const @safe pure nothrow @nogcReturns the parsed metadata.
size_t pageCount() const @safe pure nothrowReturns the number of pages.
const(OdfSettings) settings() @property ref const @safe pure nothrow @nogcReturns the parsed document settings.
void save(string path)Saves this drawing document to the given file path.
void setMimeType(string mt) @safe pure nothrow
void setBody(OdfDrawingBody body) @safe pure nothrow
void setStyles(OdfStyles styles) @safe pure nothrow
void setMetadata(OdfMetadata metadata) @safe pure nothrow
void setSettings(OdfSettings settings) @safe pure nothrow
void setDocumentType(OdfDocumentType dt) @safe pure nothrow

Represents an opened ODP presentation document with typed access to slides, styles, metadata, and settings.

Use openOdfPresentationDocument to create instances from .odp files.

Fields
private string _mimeType
private OdfPresentationBody _body
private OdfStyles _styles
private OdfMetadata _metadata
private OdfSettings _settings
private OdfDocumentType _docType
Methods
string mimeType() @property const @safe pure nothrow @nogcReturns the MIME type.
OdfDocumentType documentType() @property const @safe pure nothrow @nogcReturns the document type (PRESENTATION or PRESENTATION_TEMPLATE).
const(OdfPresentationBody) body() @property ref const @safe pure nothrow @nogcReturns the parsed presentation body.
const(OdfStyles) styles() @property ref const @safe pure nothrow @nogcReturns the parsed styles.
const(OdfMetadata) metadata() @property ref const @safe pure nothrow @nogcReturns the parsed metadata.
size_t slideCount() const @safe pure nothrowReturns the number of slides.
const(OdfSettings) settings() @property ref const @safe pure nothrow @nogcReturns the parsed document settings.
void save(string path)Saves this presentation document to the given file path.
void setMimeType(string mt) @safe pure nothrow
void setBody(OdfPresentationBody body) @safe pure nothrow
void setStyles(OdfStyles styles) @safe pure nothrow
void setMetadata(OdfMetadata metadata) @safe pure nothrow
void setSettings(OdfSettings settings) @safe pure nothrow
void setDocumentType(OdfDocumentType dt) @safe pure nothrow

Represents an opened ODC chart document with typed access to chart content, styles, metadata, and settings.

Fields
private string _mimeType
private OdfChartBody _body
private OdfStyles _styles
private OdfMetadata _metadata
private OdfSettings _settings
private OdfDocumentType _docType
Methods
string mimeType() @property const @safe pure nothrow @nogc
OdfDocumentType documentType() @property const @safe pure nothrow @nogc
const(OdfChartBody) body() @property ref const @safe pure nothrow @nogc
const(OdfStyles) styles() @property ref const @safe pure nothrow @nogc
const(OdfMetadata) metadata() @property ref const @safe pure nothrow @nogc
const(OdfSettings) settings() @property ref const @safe pure nothrow @nogcReturns the parsed document settings.
void save(string path)
void setMimeType(string mt) @safe pure nothrow
void setBody(OdfChartBody body) @safe pure nothrow
void setStyles(OdfStyles styles) @safe pure nothrow
void setMetadata(OdfMetadata metadata) @safe pure nothrow
void setSettings(OdfSettings settings) @safe pure nothrow
void setDocumentType(OdfDocumentType dt) @safe pure nothrow

Represents an opened ODF formula document (.odf).

Formula documents contain MathML markup representing mathematical formulas. Use openOdfFormulaDocument to create instances from .odf files.

Fields
private string _mimeType
private OdfFormulaBody _body
private OdfStyles _styles
private OdfMetadata _metadata
private OdfSettings _settings
private OdfDocumentType _docType
Methods
string mimeType() @property const @safe pure nothrow @nogc
OdfDocumentType documentType() @property const @safe pure nothrow @nogc
const(OdfFormulaBody) body() @property ref const @safe pure nothrow @nogc
const(OdfStyles) styles() @property ref const @safe pure nothrow @nogc
const(OdfMetadata) metadata() @property ref const @safe pure nothrow @nogc
const(OdfSettings) settings() @property ref const @safe pure nothrow @nogcReturns the parsed document settings.
void save(string path)
void setMimeType(string mt) @safe pure nothrow
void setBody(OdfFormulaBody body) @safe pure nothrow
void setStyles(OdfStyles styles) @safe pure nothrow
void setMetadata(OdfMetadata metadata) @safe pure nothrow
void setSettings(OdfSettings settings) @safe pure nothrow
void setDocumentType(OdfDocumentType dt) @safe pure nothrow

Represents an opened ODF image document (.odi).

Image documents wrap a single raster or vector image inside an ODF package. Use openOdfImageDocument to create instances from .odi files.

Fields
private string _mimeType
private OdfImageBody _body
private OdfMetadata _metadata
private OdfDocumentType _docType
Methods
string mimeType() @property const @safe pure nothrow @nogc
OdfDocumentType documentType() @property const @safe pure nothrow @nogc
const(OdfImageBody) body() @property ref const @safe pure nothrow @nogc
const(OdfMetadata) metadata() @property ref const @safe pure nothrow @nogc
void save(string path)
void setMimeType(string mt) @safe pure nothrow
void setBody(OdfImageBody body) @safe pure nothrow
void setMetadata(OdfMetadata metadata) @safe pure nothrow
void setDocumentType(OdfDocumentType dt) @safe pure nothrow

Represents an opened ODF database document (.odb).

Database documents store connection settings, queries, and table definitions in a preservation-first model. Use openOdfDatabaseDocument to create instances from .odb files.

Fields
private string _mimeType
private OdfDatabaseBody _body
private OdfMetadata _metadata
private OdfSettings _settings
private OdfDocumentType _docType
Methods
string mimeType() @property const @safe pure nothrow @nogc
OdfDocumentType documentType() @property const @safe pure nothrow @nogc
const(OdfDatabaseBody) body() @property ref const @safe pure nothrow @nogc
const(OdfMetadata) metadata() @property ref const @safe pure nothrow @nogc
const(OdfSettings) settings() @property ref const @safe pure nothrow @nogcReturns the parsed document settings.
void save(string path)
void setMimeType(string mt) @safe pure nothrow
void setBody(OdfDatabaseBody body) @safe pure nothrow
void setMetadata(OdfMetadata metadata) @safe pure nothrow
void setSettings(OdfSettings settings) @safe pure nothrow
void setDocumentType(OdfDocumentType dt) @safe pure nothrow

Functions 24

fnOdfTextDocument openOdfTextDocument(string path)Opens an ODT text document from a file path.
fnOdfTextDocument openOdfTextDocument(string path, OdfReadOptions options, ref OdfDiagnosticCollector diagnostics)Opens an ODT text document with read options and version-aware compatibility reporting.
fnOdfSpreadsheetDocument openOdfSpreadsheetDocument(string path, OdfReadOptions options, ref OdfDiagnosticCollector diagnostics)Opens an ODS spreadsheet document with read options and version-aware compatibility reporting.
fnOdfTextDocument createTextDocument(TextNode[] nodes...)Creates a new `OdfTextDocument` with the given body nodes.
fnOdfTextDocument createTextTemplate(TextNode[] nodes...)Creates a new `OdfTextDocument` as a text template (`.ott`).
fnOdfSpreadsheetDocument openOdfSpreadsheetDocument(string path)Opens an ODS spreadsheet document from a file path.
fnOdfSpreadsheetDocument createSpreadsheetDocument( SpreadsheetSheet[] sheets...)Creates a new `OdfSpreadsheetDocument` with the given sheets.
fnOdfSpreadsheetDocument createSpreadsheetTemplate( SpreadsheetSheet[] sheets...)Creates a new `OdfSpreadsheetDocument` as a spreadsheet template (`.ots`).
fnOdfDrawingDocument openOdfDrawingDocument(string path)Opens an ODG drawing document from a file path.
fnOdfDrawingDocument createDrawingDocument(DrawPage[] pages...)Creates a new `OdfDrawingDocument` with the given pages.
fnOdfDrawingDocument createDrawingTemplate(DrawPage[] pages...)Creates a new `OdfDrawingDocument` as a drawing template (`.otg`).
fnOdfPresentationDocument openOdfPresentationDocument(string path)Opens an ODP presentation document from a file path.
fnOdfPresentationDocument createPresentationDocument( PresentationSlide[] slides...)Creates a new `OdfPresentationDocument` with the given slides.
fnOdfPresentationDocument createPresentationTemplate( PresentationSlide[] slides...)Creates a new `OdfPresentationDocument` as a presentation template (`.otp`).
fnOdfChartDocument openOdfChartDocument(string path)Opens an ODF chart document from a file path.
fnOdfChartDocument createChartDocument(OdfChartBody chartBody)Creates a new `OdfChartDocument` with the given chart body.
fnOdfFormulaDocument openOdfFormulaDocument(string path)Opens an ODF formula document from a file path.
fnOdfFormulaDocument createFormulaDocument(OdfFormulaBody formulaBody)Creates a new `OdfFormulaDocument` with the given formula body.
fnOdfImageDocument openOdfImageDocument(string path)Opens an ODF image document from a file path.
fnOdfImageDocument createImageDocument(OdfImageBody imgBody)Creates a new `OdfImageDocument` with the given image body.
fnOdfDatabaseDocument openOdfDatabaseDocument(string path)Opens an ODF database document from a file path.
fnOdfDatabaseDocument createDatabaseDocument()Creates a new empty `OdfDatabaseDocument`.
fnOdfDocument openOdfDocument(string path)Opens an ODF document from a file on disk.
fnOdfDocument createOdfDocument(OdfDocumentType docType) @safe pureCreates a new empty ODF document of the given type.