#excel #xlsx

xlsxwriter

Write xlsx file with number, formula, string, formatting, autofilter, merged cells, data validation and more

8 releases

0.3.5 Jul 13, 2021
0.3.4 Jun 20, 2021
0.3.3 Apr 18, 2021
0.3.2 Sep 24, 2020
0.1.0 Nov 17, 2019

#49 in Encoding

Download history 472/week @ 2021-06-08 425/week @ 2021-06-15 430/week @ 2021-06-22 237/week @ 2021-06-29 188/week @ 2021-07-06 425/week @ 2021-07-13 444/week @ 2021-07-20 433/week @ 2021-07-27 500/week @ 2021-08-03 351/week @ 2021-08-10 614/week @ 2021-08-17 404/week @ 2021-08-24 303/week @ 2021-08-31 344/week @ 2021-09-07 374/week @ 2021-09-14 452/week @ 2021-09-21

1,702 downloads per month
Used in 2 crates

Apache-2.0

2MB
42K SLoC

C 39K SLoC // 0.2% comments Rust 3K SLoC // 0.0% comments Shell 424 SLoC // 0.2% comments Perl 233 SLoC // 0.2% comments Automake 33 SLoC

xlsxwriter-rs

Build GitHub GitHub top language Crates.io Docs.rs

Rust binding of libxlsxwriter

Supported Features

  • 100% compatible Excel XLSX files.
  • Full Excel formatting.
  • Merged cells.
  • Autofilters.
  • Data validation and drop down lists.
  • Worksheet PNG/JPEG images.

Coming soon

  • Charts.

Feature Flags

  • no-md5: Disable image de-duplication and remove md5 function. (See upstream document to learn more).
  • use-openssl-md5: Use OpenSSL implementation of md5 function. (See upstream document to learn more).
  • system-zlib: Use system zlib instead of included zlib.

Build requirements

  • LLVM and clang

How to build on windows

  1. Install Visual Studio
  2. Install LLVM
  3. Set environment variable LIBCLANG_PATH as C:\Program Files\LLVM\bin
  4. Run build

Example

Result Image

let workbook = Workbook::new("target/simple1.xlsx");
let format1 = workbook.add_format().set_font_color(FormatColor::Red);

let format2 = workbook
    .add_format()
    .set_font_color(FormatColor::Blue)
    .set_underline(FormatUnderline::Single);

let format3 = workbook
    .add_format()
    .set_font_color(FormatColor::Green)
    .set_align(FormatAlignment::CenterAcross)
    .set_align(FormatAlignment::VerticalCenter);

let mut sheet1 = workbook.add_worksheet(None)?;
sheet1.write_string(0, 0, "Red text", Some(&format1))?;
sheet1.write_number(0, 1, 20., None)?;
sheet1.write_formula_num(1, 0, "=10+B1", None, 30.)?;
sheet1.write_url(
    1,
    1,
    "https://github.com/informationsea/xlsxwriter-rs",
    Some(&format2),
)?;
sheet1.merge_range(2, 0, 3, 2, "Hello, world", Some(&format3))?;

sheet1.set_selection(1, 0, 1, 2);
sheet1.set_tab_color(FormatColor::Cyan);
workbook.close()?;

Run Example with Cargo

You can explore this example locally following the steps below:

  1. Install LLVM and set LIBCLANG_PATH if you are using windows. (see bindgen doc for details)
  2. clone or fork this repository
  3. git submodule update --init --recursive
    • The above command downloads the required C library so we can compile
  4. cargo run --example hello_spreadsheet

You should then see the example in target/simple1.xlsx. Enjoy!

Dependencies

~0–1.5MB
~32K SLoC