1use anyhow::Result;
2
3#[derive(Debug, Clone, Default)]
5pub struct CellStyle {
6 pub bold: bool,
8 pub italic: bool,
10 pub bg_color: Option<String>,
12 pub font_color: Option<String>,
14 pub font_size: Option<f64>,
16 pub border: bool,
18 pub align: Option<String>,
20 pub number_format: Option<String>,
22}
23
24impl CellStyle {
25 pub fn header() -> Self {
26 Self {
27 bold: true,
28 bg_color: Some("4472C4".to_string()),
29 font_color: Some("FFFFFF".to_string()),
30 border: true,
31 align: Some("center".to_string()),
32 ..Default::default()
33 }
34 }
35
36 pub fn parse_hex_color(hex: &str) -> Result<u32> {
38 let hex = hex.trim_start_matches('#');
39 if hex.len() != 6 {
40 anyhow::bail!("Invalid hex color: {}", hex);
41 }
42 let r = u8::from_str_radix(&hex[0..2], 16)?;
43 let g = u8::from_str_radix(&hex[2..4], 16)?;
44 let b = u8::from_str_radix(&hex[4..6], 16)?;
45 Ok(r as u32 * 0x10000 + g as u32 * 0x100 + b as u32)
46 }
47}
48
49#[derive(Debug, Clone)]
51pub struct WriteOptions {
52 pub sheet_name: Option<String>,
54 pub style_header: bool,
56 pub header_style: CellStyle,
58 pub column_styles: Option<std::collections::HashMap<usize, CellStyle>>,
60 pub freeze_header: bool,
62 pub auto_filter: bool,
64 pub auto_fit: bool,
66}
67
68impl Default for WriteOptions {
69 fn default() -> Self {
70 Self {
71 sheet_name: None,
72 style_header: true,
73 header_style: CellStyle::header(),
74 column_styles: None,
75 freeze_header: false,
76 auto_filter: false,
77 auto_fit: true,
78 }
79 }
80}