simple-xlsx-writer

Crates.iosimple-xlsx-writer
lib.rssimple-xlsx-writer
version0.1.2
sourcesrc
created_at2022-11-28 20:43:35.420086
updated_at2024-01-02 19:03:54.31162
descriptionA simple and memory efficient XLSX writer
homepage
repositoryhttps://github.com/killertux/simple-xlsx-writer
max_upload_size
id724756
size52,818
Bruno Clemente (killertux)

documentation

README

simple_xlsx_writer

This is a very simple XLSX writer library.

This is not feature rich and it is not supposed to be. A lot of the design was based on the work of simple_excel_writer and I recomend you to check that crate.

The main idea of this create is to help you build XLSX files using very little RAM. I created it to use in my web assembly site csv2xlsx.

Basically, you just need to pass an output that implements Write and Seek to the WorkBook. And while you are writing the file, it wil be written directly to the output already compressed. So, you could stream directly into a file using very little RAM. Or even write to the memory and still not use that much memory as the file will be already compressed.

Example

use simple_xlsx_writer::{row, Row, WorkBook};
use std::fs::File;
use std::io::Write;

fn main() -> std::io::Result<()> {
 let mut files = File::create("example.xlsx")?;
 let mut workbook = WorkBook::new(&mut files)?;
 let header_style = workbook.create_cell_style((255, 255, 255), (0, 0, 0));
 workbook.get_new_sheet().write_sheet(|sheet_writer| {
     sheet_writer.write_row(row![("My", &header_style), ("Sample", &header_style), ("Header", &header_style)])?;
     sheet_writer.write_row(row![1, 2, 3])?;
     Ok(())
 })?;
 workbook.get_new_sheet().write_sheet(|sheet_writer| {
     sheet_writer.write_row(row![("Another", &header_style), ("Sheet", &header_style), ("Header", &header_style)])?;
     sheet_writer.write_row(row![1.32, 2.43, 3.54])?;
     Ok(())
 })?;
 workbook.finish()?;
 files.flush()?;
 Ok(())
}
Commit count: 0

cargo fmt