Expand description
RightKit documents: read and write DOCX, XLSX and PDF behind one typed API, for agents and apps that must not trust the files they open.
use std::path::Path;
use rightkit_docs::{read, write, Block, Op, ReadOptions, Source, WriteOptions};
let path = Path::new("report.docx");
write(path, &[Op::CreateDocx { blocks: vec![Block::Heading { level: 1, text: "Q3".into() }] }],
&WriteOptions::default())?;
let doc = read(Source::Path(path), &ReadOptions::default())?;
// Edit against exactly what was read: refuses if the file changed in between.
write(path, &[Op::ReplaceText { find: "Q3".into(), replace: "Q4".into() }],
&WriteOptions { expect_sha256: Some(doc.sha256), ..Default::default() })?;| module | responsibility |
|---|---|
detect | format from content: PDF, DOCX, XLSX; refuses macros, encryption, the rest |
package | OOXML zip preflight (entries, sizes, ratio, names, DOCTYPE) and raw rewrite |
docx | read, create, append blocks, replace text by byte-range patch |
xlsx | read (calamine), create (rust_xlsxwriter), set cells and append rows in place |
pdf | facade over rightkit-pdf: extract, replace text, add text, select pages |
Every write is built in memory, validated by re-detecting it, and published once through
rightkit_fs::AtomicWriter after a last source-hash recheck.
Structs§
- Cell
Read - CellSet
- Document
Read - Docx
Content - Limits
- Caps on one input file. The defaults suit documents a person or an agent opens; raise them per call, never process-wide.
- Loss
- Something the edit could not keep, or deliberately changed. Empty
lossesmeans every part the edit did not touch is byte-identical to the source. - PdfContent
- PdfPage
Text - Read
Options - Page, sheet and range selection plus the output caps.
- Sheet
Read - Sheet
Spec - Write
Options - Write
Receipt - Xlsx
Content
Enums§
- Block
- A block of new DOCX content.
- Cell
Input - A value to write into a cell.
Textis always a string, whatever it starts with: onlyFormulais a formula. - Cell
Value - Content
- Docs
Error - Everything
readandwritecan refuse. Every variant has a stableDocsError::code. - Docx
Block - Format
- Op
- One typed write op. A
writecall applies its ops in order to one in-memory document and publishes the result once. - Source
- Where
readgets its bytes. The format is detected from the content, never the file name.
Functions§
- read
- Read a DOCX, XLSX or PDF. The format comes from the bytes; the file name is never consulted.
- write
- Apply typed ops to
targetand publish the result atomically.