office-toolkit 1.0.0

A Rust library to create, read, and modify Microsoft Office documents (Word/Excel/PowerPoint) in the modern Open XML (OOXML) format.
Documentation
//! The simplest possible PowerPoint presentation: one slide, one text
//! shape, saved to a real `.pptx` file, then read back to prove the file
//! this crate wrote is valid and round-trips correctly.
//!
//! Run with: `cargo run -p office-toolkit --example hello_world_pptx`

use std::path::{Path, PathBuf};

use office_toolkit::drawing::{ShapeProperties, TextBody, TextParagraph, TextRun, Transform2D};
use office_toolkit::powerpoint::{AutoShape, Shape};
use office_toolkit::prelude::*;
use office_toolkit::{OpenFile, SaveToFile};

fn main() -> office_toolkit::Result<()> {
    let path = output_path("hello_world.pptx");

    let text_box = AutoShape::new(2, "Hello box")
        .with_properties(
            ShapeProperties::new().with_transform(
                Transform2D::new()
                    .with_offset(838_200, 1_365_250)
                    .with_extent(7_772_400, 1_200_150),
            ),
        )
        .with_text_body(
            TextBody::new()
                .with_paragraph(TextParagraph::new().with_run(TextRun::text("Hello, world!"))),
        );

    // `Presentation` and `Slide` both come from `office_toolkit::prelude`.
    let presentation =
        Presentation::new().with_slide(Slide::new().with_shape(Shape::AutoShape(text_box)));
    presentation.save_to_file(&path)?;
    println!("Wrote {}", path.display());

    // Read the file back to confirm it is a valid .pptx.
    let reopened = Presentation::open_file(&path)?;
    println!("Slide count: {}", reopened.slides.len());

    Ok(())
}

/// Every example in this directory writes its output under
/// `tests-data/output/`, resolved relative to this crate's own manifest so
/// it works no matter what directory `cargo run` was invoked from.
fn output_path(filename: &str) -> PathBuf {
    Path::new(env!("CARGO_MANIFEST_DIR"))
        .join("../../tests-data/output")
        .join(filename)
}