Expand description
Writes what a grid shows as a file.
The table comes from datagrid_core::export_table, which takes the
visible columns in the order the grid lays them out and the rows as sorted,
filtered and grouped. This crate only writes it: each format is a feature, so
that the ones with heavy dependencies cost nothing to anyone who does not
ask for them. CSV and HTML need no dependency at all; Excel (xlsx) needs
rust_xlsxwriter.
use datagrid_core::{
CellValue, ColumnSpec, ExportScope, GridLocale, GridState, export_table,
};
use datagrid_export::{CsvOptions, to_csv};
struct Person {
name: &'static str,
age: i64,
}
let rows = [Person { name: "Zoe", age: 31 }, Person { name: "Adi", age: 27 }];
let columns = [
ColumnSpec::new("name").value(|row: &Person| CellValue::Text(row.name)),
ColumnSpec::new("age").value(|row: &Person| CellValue::Int(row.age)),
];
let table = export_table(
&rows,
&columns,
|id| id.as_str().to_owned(),
&GridState::new(),
&GridLocale::english(),
ExportScope::Filtered,
);
assert_eq!(to_csv(&table, &CsvOptions::default()), "name,age\r\nZoe,31\r\nAdi,27\r\n");Structs§
- CsvOptions
- How
to_csvwrites. - Html
Options - How
to_htmlwrites.
Enums§
- CsvValues
- What the cells say.
- Line
Ending - How a line ends.
Constants§
- PRINT_
CSS - The rules a document needs to print well: the header repeats on every page, a row stays whole, numbers line up.