jmcnamara / rust_xlsxwriter

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

Feature request: utility::validate_sheetname visibility #83

Closed barsa-net closed 5 months ago

barsa-net commented 5 months ago

Question

Currently utility::validate_sheetname visibility is set as pub(crate), would it be possible in a future release to make it just pub?

I ask this because in my current use case I would like to check a sheet name validity before using set_name() without the need to reimplement the same logic of validate_sheetname().

jmcnamara commented 5 months ago

would it be possible in a future release to make it just pub?

Sure. I can do that. I'll just need to change the error handling around a bit. I'll add it in the next release.

jmcnamara commented 5 months ago

I've added a public utility::check_sheet_name() function to main.

Example:


use rust_xlsxwriter::{utility, XlsxError};

fn main() -> Result<(), XlsxError> {
    // This worksheet name is valid.
    utility::check_sheet_name("2030-01-01")?;

    // This worksheet name isn't valid due to the forward slashes.
    utility::check_sheet_name("2030/01/01")?;

    Ok(())
}

Output:

$ cargo run --example doc_utility_check_sheet_name
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
     Running `target/debug/examples/doc_utility_check_sheet_name`

Error: SheetnameContainsInvalidCharacter("Invalid Excel worksheet name '2030/01/01'")

Let me know if that works for you.

barsa-net commented 5 months ago

That works perfectly, thanks!

jmcnamara commented 5 months ago

Thanks for testing. I will close the request. The feature will be in the next release.

jmcnamara commented 5 months ago

This is now upstream in v0.63.0. Thanks for the input.