Skip to main content

to_csv

Function to_csv 

Source
pub fn to_csv(table: &ExportTable, options: &CsvOptions) -> String
Expand description

Writes the table as CSV.

One line per data row, under a line of the column labels. A group’s heading is a line of its own with the caption in the first field, and its aggregates follow its rows as a line with each in its column’s field: Sum €7,300.50, or several of them joined with ; . The totals line starts with the locale’s “Totals”. Where the table has no groups, none of that shows.

use datagrid_core::{ExportCell, ExportColumn, ExportRow, ExportTable, Value};
use datagrid_export::{CsvOptions, to_csv};

let table = ExportTable {
    columns: vec![ExportColumn::new("note", "note")],
    rows: vec![ExportRow::Data(vec![ExportCell {
        value: Some(Value::Text("said \"hi\", left".into())),
        text: "said \"hi\", left".into(),
    }])],
};
assert_eq!(
    to_csv(&table, &CsvOptions::default()),
    "note\r\n\"said \"\"hi\"\", left\"\r\n",
);