Skip to main content

Crate rightkit_docs

Crate rightkit_docs 

Source
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() })?;
moduleresponsibility
detectformat from content: PDF, DOCX, XLSX; refuses macros, encryption, the rest
packageOOXML zip preflight (entries, sizes, ratio, names, DOCTYPE) and raw rewrite
docxread, create, append blocks, replace text by byte-range patch
xlsxread (calamine), create (rust_xlsxwriter), set cells and append rows in place
pdffacade 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§

CellRead
CellSet
DocumentRead
DocxContent
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 losses means every part the edit did not touch is byte-identical to the source.
PdfContent
PdfPageText
ReadOptions
Page, sheet and range selection plus the output caps.
SheetRead
SheetSpec
WriteOptions
WriteReceipt
XlsxContent

Enums§

Block
A block of new DOCX content.
CellInput
A value to write into a cell. Text is always a string, whatever it starts with: only Formula is a formula.
CellValue
Content
DocsError
Everything read and write can refuse. Every variant has a stable DocsError::code.
DocxBlock
Format
Op
One typed write op. A write call applies its ops in order to one in-memory document and publishes the result once.
Source
Where read gets 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 target and publish the result atomically.

Type Aliases§

Result