excel_add_sheet 0.1.0

A library for adding worksheets to existing Excel (XLSX) files.
Documentation
# excel_add_sheet


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

[![Crates.io](https://img.shields.io/crates/v/excel_add_sheet.svg)](https://crates.io/crates/excel_add_sheet)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

## 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`:

```toml
[dependencies]
excel_add_sheet = "0.1.0"
```

## Usage


### Add a Worksheet to an Existing File

```rust
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

```rust
use excel_add_sheet::ExcelDoc;

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

### Overwrite an Existing File

```rust
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](LICENSE) for details.

---

**Author:** Joey Clemens (<joeyclemens@tuta.io>)

[Repository](https://github.com/joeyclemens/excel_add_sheet)