simple excel writer in Rust
#[macro_use]
extern crate simple_excel_writer as excel;
use excel::*;
fn main() {
let mut wb = Workbook::create("/tmp/b.xlsx");
let mut sheet = wb.create_sheet("SheetName");
// set column width
sheet.add_column(Column { width: 30.0 });
sheet.add_column(Column { width: 30.0 });
sheet.add_column(Column { width: 80.0 });
sheet.add_column(Column { width: 60.0 });
wb.write_sheet(&mut sheet, |sheet_writer| {
let sw = sheet_writer;
sw.append_row(row!["Name", "Title","Success","XML Remark"])?;
sw.append_row(row!["Amy", (), true,"<xml><tag>\"Hello\" & 'World'</tag></xml>"])?;
sw.append_blank_rows(2);
sw.append_row(row!["Tony", blank!(2), "retired"])
}).expect("write excel error!");
let mut sheet = wb.create_sheet("Sheet2");
wb.write_sheet(&mut sheet, |sheet_writer| {
let sw = sheet_writer;
sw.append_row(row!["Name", "Title","Success","Remark"])?;
sw.append_row(row!["Amy", "Manager", true])
}).expect("write excel error!");
let euro_fmt_idx = wb.add_cust_number_format("\"€\"#,##0.00".to_string());
let weight_fmt_idx = wb.add_cust_number_format("#,##0.0\" KG\"".to_string());
let mut sheet_num_fmt = wb.create_sheet("SheetNumFormatted");
sheet_num_fmt.add_column(Column { width: 30.0 });
sheet_num_fmt.add_column(Column { width: 30.0 });
wb.write_sheet(&mut sheet_num_fmt, |sheet_writer| {
let sw = sheet_writer;
sw.append_row(row!["Weight", "Price"])?;
sw.append_row(row![(700.5, weight_fmt_idx), (12045.99, euro_fmt_idx)])?;
sw.append_row(row![(1525.0, weight_fmt_idx), (25999.00, euro_fmt_idx)])
}).expect("write excel error!");
wb.close().expect("close excel error!");
}
- support style
- support WASM !
- support formula
- support NaiveDate & NaiveDateTime
- format dates and date times
- Sheet name validation
- remove unndecessary bzip2 dependency
many thanks to all contributors !
- support create-in-memory mode, thanks to Maxburke.
This change creates all worksheet files in-memory and only writes them
to disk once the XLSX file is closed.
A new option for creating a version that is in-memory only is available
with `Worksheet::create_in_memory()` which returns the buffer holding
the completed XLSX file contents when closed.
- support shared strings between worksheets, thanks to Mikael Edlund.
- support Windows platform, thanks to Carl Fredrik Samson.
- escape xml characters.
- support 26+ columns .
- fix column width bug.
- support multiple sheets
- generate the basic xlsx file
Apache-2.0