#xlsx #excel #polars

polars_excel_writer

A Polars extension to serialize dataframes to Excel xlsx files

24 breaking releases

0.25.0 Feb 28, 2026
0.23.0 Jan 27, 2026
0.22.0 Nov 17, 2025
0.17.0 Jul 27, 2025
0.4.0 Nov 22, 2023

#181 in Date and time

Download history 157/week @ 2026-02-17 1018/week @ 2026-02-24 830/week @ 2026-03-03 545/week @ 2026-03-10 22/week @ 2026-03-17 1/week @ 2026-03-24 26/week @ 2026-03-31 90/week @ 2026-04-07 106/week @ 2026-04-14 2/week @ 2026-04-21 50/week @ 2026-04-28 52/week @ 2026-05-05 89/week @ 2026-05-12 184/week @ 2026-05-19 376/week @ 2026-05-26 1370/week @ 2026-06-02

2,025 downloads per month

MIT/Apache

145KB
483 lines

polars_excel_writer

The polars_excel_writer crate is a library for serializing Polars dataframes to Excel Xlsx files.

The crate uses rust_xlsxwriter to do the Excel serialization and is typically 5x faster than Polars when exporting large dataframes to Excel.

It provides a primary interface PolarsExcelWriter which is a configurable Excel serializer that resembles the interface options provided by the Polars write_excel() dataframe method.

Example

An example of writing a Polar Rust dataframe to an Excel file using the PolarsExcelWriter interface.

use chrono::prelude::*;
use polars::prelude::*;

use polars_excel_writer::PolarsExcelWriter;

fn main() -> PolarsResult<()> {
    // Create a sample dataframe for the example.
    let df: DataFrame = df!(
        "String" => &["North", "South", "East", "West"],
        "Integer" => &[1, 2, 3, 4],
        "Float" => &[4.0, 5.0, 6.0, 7.0],
        "Time" => &[
            NaiveTime::from_hms_milli_opt(2, 59, 3, 456).unwrap(),
            NaiveTime::from_hms_milli_opt(2, 59, 3, 456).unwrap(),
            NaiveTime::from_hms_milli_opt(2, 59, 3, 456).unwrap(),
            NaiveTime::from_hms_milli_opt(2, 59, 3, 456).unwrap(),
            ],
        "Date" => &[
            NaiveDate::from_ymd_opt(2022, 1, 1).unwrap(),
            NaiveDate::from_ymd_opt(2022, 1, 2).unwrap(),
            NaiveDate::from_ymd_opt(2022, 1, 3).unwrap(),
            NaiveDate::from_ymd_opt(2022, 1, 4).unwrap(),
            ],
        "Datetime" => &[
            NaiveDate::from_ymd_opt(2022, 1, 1).unwrap().and_hms_opt(1, 0, 0).unwrap(),
            NaiveDate::from_ymd_opt(2022, 1, 2).unwrap().and_hms_opt(2, 0, 0).unwrap(),
            NaiveDate::from_ymd_opt(2022, 1, 3).unwrap().and_hms_opt(3, 0, 0).unwrap(),
            NaiveDate::from_ymd_opt(2022, 1, 4).unwrap().and_hms_opt(4, 0, 0).unwrap(),
        ],
    )?;

    // Create a new Excel writer.
    let mut excel_writer = PolarsExcelWriter::new();

    // Write the dataframe to Excel.
    excel_writer.write_dataframe(&df)?;

    // Save the file to disk.
    excel_writer.save("dataframe.xlsx")?;

    Ok(())
}

Output file:

Performance

The table below shows the performance of writing a dataframe using Python Polars, Python Pandas and PolarsExcelWriter.

Test Case Time (s) Relative (%)
Polars 6.49 100%
Pandas 10.92 168%
polars_excel_writer 1.22 19%
polars_excel_writer + zlib 1.08 17%

See the Performance section of the docs for more detail.

See also

Dependencies

~58MB
~840K SLoC