// Test case that compares a file generated by polars_excel_writer with a file // created by Excel. // // SPDX-License-Identifier: MIT OR Apache-2.0 // // Copyright 2023-2024, John McNamara, jmcnamara@cpan.org use crate::common; use polars::prelude::*; use polars_excel_writer::PolarsXlsxWriter; use rust_xlsxwriter::{Table, TableColumn, TableFunction, TableStyle, XlsxError}; // Compare output against target Excel file using PolarsXlsxWriter. fn create_new_xlsx_file(filename: &str) -> Result<(), XlsxError> { let df: DataFrame = df!( "Foo" => &[2, -1, -1], "Bar" => &[2, 2, -4], )?; let mut xlsx_writer = PolarsXlsxWriter::new(); let columns = vec![ TableColumn::new().set_total_function(TableFunction::Sum), TableColumn::new().set_total_function(TableFunction::Sum), ]; let table = Table::new() .set_style(TableStyle::None) .set_first_column(true) .set_last_column(true) .set_total_row(true) .set_columns(&columns); xlsx_writer.set_table(&table); xlsx_writer.write_dataframe(&df)?; xlsx_writer.save(filename)?; Ok(()) } #[test] fn dataframe_write_excel05() { let test_runner = common::TestRunner::new() .set_name("dataframe05") .set_function(create_new_xlsx_file) .ignore_calc_chain() .initialize(); test_runner.assert_eq(); test_runner.cleanup(); }