Skip to main content

open

Function open 

Source
pub fn open(path: impl AsRef<Path>) -> Result<OfficeDocument>
Expand description

Opens a .docx/.xlsx/.pptx file, detecting its format from the OPC package’s own parts (word/document.xml/xl/workbook.xml/ ppt/presentation.xml) rather than from the file’s extension or name — a renamed or extension-less file still opens correctly, and a file carrying none of the three is reported as Error::UnrecognizedFormat rather than silently misidentified as one of them. A file whose format is recognized, but whose matching Cargo feature isn’t enabled in this build, is reported as Error::FormatNotEnabled instead — a more useful answer than pretending the file doesn’t exist.

Reads the whole file into memory once to inspect it (opc::Package keeps every part’s bytes resident regardless), then re-parses those same already-read bytes through the matching format crate’s own read_from — a second, format-specific parse, not a second read from disk.