excel_add_sheet

Crates.ioexcel_add_sheet
lib.rsexcel_add_sheet
version0.1.0
created_at2025-07-14 12:47:47.806458+00
updated_at2025-07-14 12:47:47.806458+00
descriptionA library for adding worksheets to existing Excel (XLSX) files.
homepage
repositoryhttps://github.com/joeyclemens/excel_add_sheet
max_upload_size
id1751644
size120,167
(joeyclemens)

documentation

README

excel_add_sheet

A Rust library for adding worksheets to existing Excel (XLSX) files.

Crates.io License: MIT

Features

  • Add new worksheets to existing .xlsx files
  • Insert data into new worksheets (2D string arrays)
  • Save modified workbooks to new or existing files
  • List files inside an XLSX archive
  • Minimal dependencies: only zip, quick-xml, and tempfile

Installation

Add to your Cargo.toml:

[dependencies]
excel_add_sheet = "0.1.0"

Usage

Add a Worksheet to an Existing File

use excel_add_sheet::ExcelDoc;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Open the Excel file
    let mut doc = ExcelDoc::open("minimal.xlsx")?;

    // Add a new worksheet with some data
    let data = vec![
        vec!["Hello".to_string(), "World".to_string()],
        vec!["123".to_string(), "456".to_string()],
    ];
    doc.add_worksheet("NewSheet", Some(data))?;

    // Save as a new file
    doc.save("modified.xlsx")?;

    println!("Added worksheet and saved as modified.xlsx!");
    Ok(())
}

List Files in an XLSX Archive

use excel_add_sheet::ExcelDoc;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    ExcelDoc::print_file_list("modified.xlsx")
}

Overwrite an Existing File

use excel_add_sheet::ExcelDoc;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let path = "minimal.xlsx";
    let mut doc = ExcelDoc::open(path)?;
    let data = vec![
        vec!["Scripted".to_string(), "Sheet".to_string()],
        vec!["123".to_string(), "456".to_string()],
    ];
    doc.add_worksheet("ScriptSheet", Some(data))?;
    doc.save(path)?;
    Ok(())
}

API Overview

ExcelDoc

  • ExcelDoc::open(path) -> Result<ExcelDoc, _>: Open an existing XLSX file for modification.
  • add_worksheet(name, data): Add a worksheet with a given name and optional 2D string data.
  • add_blank_worksheet(name): Add a blank worksheet.
  • save(path): Save the modified document to a file.
  • print_file_list(path): Print the list of files in the XLSX archive.

ExcelWorkbook and Worksheet

For advanced manipulation, you can use the ExcelWorkbook and Worksheet structs to work with sheets and cells directly.

License

MIT License. See LICENSE for details.


Author: Joey Clemens (joeyclemens@tuta.io)

Repository

Commit count: 0

cargo fmt