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
//! Word document theme: the color and font palette behind Word's own
//! "Theme Colors"/"Theme Fonts" pickers. A theme applies to a whole
//! document (like page setup), so this example writes two small files —
//! one per theme — rather than two pages of a single one.
//!
//! Run with: `cargo run -p office-toolkit --example docx_theme`

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

use office_toolkit::SaveToFile;
use office_toolkit::prelude::*;
use office_toolkit::word::{ColorScheme, FontScheme, Theme};

fn main() -> office_toolkit::Result<()> {
    let default_theme_document = Document::new()
        .with_theme(Theme::office_default())
        .with_paragraph(Paragraph::with_text("Office's built-in default theme."))
        .with_paragraph(Paragraph::with_text(
            "Cambria for headings, Calibri for body text, the classic Office palette.",
        ));
    let default_path = output_path("docx_theme_default.docx");
    default_theme_document.save_to_file(&default_path)?;
    println!("Wrote {}", default_path.display());

    // A custom, branded theme: a dark navy/orange palette and a different
    // heading/body font pairing.
    let custom_colors = ColorScheme::new(
        "1B1B1B", "FFFFFF", "0A2540", "F5F5F5", "0A2540", "E8622C", "2E86AB", "6FB98F", "F4A259",
        "8E4585", "1155CC", "6B3FA0",
    );
    let custom_fonts = FontScheme::new("Georgia", "Verdana");
    let custom_theme_document = Document::new()
        .with_theme(Theme::new("Custom Brand", custom_colors, custom_fonts))
        .with_paragraph(Paragraph::with_text("A custom, branded theme."))
        .with_paragraph(Paragraph::with_text(
            "Georgia for headings, Verdana for body text, a navy/orange palette.",
        ));
    let custom_path = output_path("docx_theme_custom.docx");
    custom_theme_document.save_to_file(&custom_path)?;
    println!("Wrote {}", custom_path.display());

    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)
}