Skip to content

Commit

Permalink
utility: add new helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcnamara committed Feb 8, 2025
1 parent 1da5e03 commit 7014f7a
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 43 deletions.
6 changes: 2 additions & 4 deletions examples/doc_utility_check_sheet_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
use rust_xlsxwriter::{utility, XlsxError};

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

assert!(matches!(result, ()));
// This worksheet name is valid and doesn't raise an error.
utility::check_sheet_name("2030-01-01")?;

// This worksheet name isn't valid due to the forward slashes.
let result = utility::check_sheet_name("2030/01/01");
Expand Down
33 changes: 33 additions & 0 deletions examples/doc_utility_quote_sheet_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright 2022-2025, John McNamara, [email protected]

//! The following example demonstrates quoting worksheet names.
use rust_xlsxwriter::utility;

fn main() {
// Doesn't need to be quoted.
let result = utility::quote_sheet_name("Sheet1");
assert_eq!(result, "Sheet1");

// Spaces need to be quoted.
let result = utility::quote_sheet_name("Sheet 1");
assert_eq!(result, "'Sheet 1'");

// Special characters need to be quoted.
let result = utility::quote_sheet_name("Sheet-1");
assert_eq!(result, "'Sheet-1'");

// Single quotes need to be escaped with a quote.
let result = utility::quote_sheet_name("Sheet'1");
assert_eq!(result, "'Sheet''1'");

// A1 style cell references don't need to be quoted.
let result = utility::quote_sheet_name("A1");
assert_eq!(result, "'A1'");

// R1C1 style cell references need to be quoted.
let result = utility::quote_sheet_name("RC1");
assert_eq!(result, "'RC1'");
}
3 changes: 2 additions & 1 deletion examples/doc_worksheet_serialize_datetime3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
//! function.
use chrono::NaiveDate;
use rust_xlsxwriter::utility::serialize_chrono_naive_to_excel;
use serde::Serialize;

use rust_xlsxwriter::utility::serialize_chrono_naive_to_excel;

fn main() {
#[derive(Serialize)]
struct Student {
Expand Down
Loading

0 comments on commit 7014f7a

Please sign in to comment.