use anyhow::Result;
#[derive(Debug, Clone, Default)]
pub struct CellStyle {
pub bold: bool,
pub italic: bool,
pub bg_color: Option<String>,
pub font_color: Option<String>,
pub font_size: Option<f64>,
pub border: bool,
pub align: Option<String>,
pub number_format: Option<String>,
}
impl CellStyle {
pub fn header() -> Self {
Self {
bold: true,
bg_color: Some("4472C4".to_string()),
font_color: Some("FFFFFF".to_string()),
border: true,
align: Some("center".to_string()),
..Default::default()
}
}
pub fn parse_hex_color(hex: &str) -> Result<u32> {
let hex = hex.trim_start_matches('#');
if hex.len() != 6 {
anyhow::bail!("Invalid hex color: {}", hex);
}
let r = u8::from_str_radix(&hex[0..2], 16)?;
let g = u8::from_str_radix(&hex[2..4], 16)?;
let b = u8::from_str_radix(&hex[4..6], 16)?;
Ok(r as u32 * 0x10000 + g as u32 * 0x100 + b as u32)
}
}
#[derive(Debug, Clone)]
pub struct WriteOptions {
pub sheet_name: Option<String>,
pub style_header: bool,
pub header_style: CellStyle,
pub column_styles: Option<std::collections::HashMap<usize, CellStyle>>,
pub freeze_header: bool,
pub auto_filter: bool,
pub auto_fit: bool,
}
impl Default for WriteOptions {
fn default() -> Self {
Self {
sheet_name: None,
style_header: true,
header_style: CellStyle::header(),
column_styles: None,
freeze_header: false,
auto_filter: false,
auto_fit: true,
}
}
}