jmcnamara / rust_xlsxwriter

A Rust library for creating Excel XLSX files.
https://crates.io/crates/rust_xlsxwriter
Apache License 2.0
316 stars 25 forks source link

feature request: impl IntoExcelData for bool #40

Closed Christoph-AK closed 1 year ago

Christoph-AK commented 1 year ago

Feature Request

Hi and thanks for the crate!

I'm currently writing an sql export tool from MSSQL to xlsx.

I would love to be able to write bools directly with sheet.write(row, col, true).

Excel should have some kind of representation for logic, maybe just the text TRUE and FALSE, but potentially some better values or cell types.

jmcnamara commented 1 year ago

I would love to be able to write bools directly with sheet.write(row, col, true).

I 100% meant to do that but somehow forgot. I've pushed an update to main with support added.

Excel should have some kind of representation for logic, maybe just the text TRUE and FALSE, but potentially some better values or cell types.

It has a boolean TRUE/FALSE type which can be written with worksheet.write_boolean() (link) and now write().

Thanks for the prompt.

jmcnamara commented 1 year ago

Example:

use rust_xlsxwriter::{Workbook, XlsxError};

fn main() -> Result<(), XlsxError> {
    let mut workbook = Workbook::new();

    // Add a worksheet to the workbook.
    let worksheet = workbook.add_worksheet();

    worksheet.write(0, 0, true)?;
    worksheet.write(1, 0, false)?;

    workbook.save("worksheet.xlsx")?;

    Ok(())
}

Output:

screenshot

Christoph-AK commented 1 year ago

Perfect, thank you so much!