use excelstream::types::{CellStyle, CellValue};
use excelstream::writer::ExcelWriter;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Creating styled Excel file...");
let mut writer = ExcelWriter::new("output_formatted.xlsx")?;
println!("Writing bold header...");
writer.write_header_bold(["Style", "Example Value", "Description"])?;
writer.write_row_styled(&[
(CellValue::String("Default".to_string()), CellStyle::Default),
(
CellValue::String("Plain text".to_string()),
CellStyle::Default,
),
(
CellValue::String("No special formatting".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("NumberInteger".to_string()),
CellStyle::Default,
),
(CellValue::Int(1234567), CellStyle::NumberInteger),
(
CellValue::String("Integer with thousand separator".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("NumberDecimal".to_string()),
CellStyle::Default,
),
(CellValue::Float(1234567.89), CellStyle::NumberDecimal),
(
CellValue::String("Decimal with 2 places".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("NumberCurrency".to_string()),
CellStyle::Default,
),
(CellValue::Float(1234.56), CellStyle::NumberCurrency),
(
CellValue::String("Currency format with $ symbol".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("NumberPercentage".to_string()),
CellStyle::Default,
),
(CellValue::Float(0.95), CellStyle::NumberPercentage),
(
CellValue::String("Percentage format (0.95 = 95%)".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("DateDefault".to_string()),
CellStyle::Default,
),
(
CellValue::Float(44927.0), CellStyle::DateDefault,
),
(
CellValue::String("Date format MM/DD/YYYY".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("DateTimestamp".to_string()),
CellStyle::Default,
),
(
CellValue::Float(44927.5), CellStyle::DateTimestamp,
),
(
CellValue::String("DateTime with time component".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("TextBold".to_string()),
CellStyle::Default,
),
(
CellValue::String("Bold Text".to_string()),
CellStyle::TextBold,
),
(
CellValue::String("Bold formatting for emphasis".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("TextItalic".to_string()),
CellStyle::Default,
),
(
CellValue::String("Italic Text".to_string()),
CellStyle::TextItalic,
),
(
CellValue::String("Italic formatting for notes".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("HighlightYellow".to_string()),
CellStyle::Default,
),
(
CellValue::String("Yellow Background".to_string()),
CellStyle::HighlightYellow,
),
(
CellValue::String("Yellow background highlight".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("HighlightGreen".to_string()),
CellStyle::Default,
),
(
CellValue::String("Green Background".to_string()),
CellStyle::HighlightGreen,
),
(
CellValue::String("Green background highlight".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("HighlightRed".to_string()),
CellStyle::Default,
),
(
CellValue::String("Red Background".to_string()),
CellStyle::HighlightRed,
),
(
CellValue::String("Red background highlight".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("BorderThin".to_string()),
CellStyle::Default,
),
(
CellValue::String("With Borders".to_string()),
CellStyle::BorderThin,
),
(
CellValue::String("Thin borders on all sides".to_string()),
CellStyle::Default,
),
])?;
writer.write_row_styled(&[
(
CellValue::String("DateTimeShort".to_string()),
CellStyle::Default,
),
(
CellValue::Float(44927.5), CellStyle::DateTimeShort,
),
(
CellValue::String("DateTime without seconds".to_string()),
CellStyle::Default,
),
])?;
writer.write_row(["", "", ""])?; writer.write_header_bold(["Convenience Method Demo"])?;
writer.write_row_with_style(
&[
CellValue::String("All".to_string()),
CellValue::String("cells".to_string()),
CellValue::String("are".to_string()),
CellValue::String("bold".to_string()),
],
CellStyle::TextBold,
)?;
writer.write_row(["", "", ""])?; writer.write_header_bold(["Item", "Amount", "Change %"])?;
writer.write_row_styled(&[
(CellValue::String("Revenue".to_string()), CellStyle::Default),
(CellValue::Float(150000.00), CellStyle::NumberCurrency),
(CellValue::Float(0.15), CellStyle::NumberPercentage),
])?;
writer.write_row_styled(&[
(
CellValue::String("Expenses".to_string()),
CellStyle::Default,
),
(CellValue::Float(95000.00), CellStyle::NumberCurrency),
(CellValue::Float(0.08), CellStyle::NumberPercentage),
])?;
writer.write_row_styled(&[
(CellValue::String("Profit".to_string()), CellStyle::TextBold),
(CellValue::Float(55000.00), CellStyle::NumberCurrency),
(CellValue::Float(0.22), CellStyle::NumberPercentage),
])?;
writer.save()?;
println!("✅ Successfully created output_formatted.xlsx");
println!(" Open the file in Excel to see all 15 cell styles!");
println!();
println!("Available styles:");
println!(" - Default: No formatting");
println!(" - HeaderBold: Bold header text");
println!(" - NumberInteger: #,##0");
println!(" - NumberDecimal: #,##0.00");
println!(" - NumberCurrency: $#,##0.00");
println!(" - NumberPercentage: 0.00%");
println!(" - DateDefault: MM/DD/YYYY");
println!(" - DateTimestamp: MM/DD/YYYY HH:MM:SS");
println!(" - TextBold: Bold text");
println!(" - TextItalic: Italic text");
println!(" - HighlightYellow: Yellow background");
println!(" - HighlightGreen: Green background");
println!(" - HighlightRed: Red background");
println!(" - BorderThin: Thin borders");
println!(" - DateTimeShort: MM/DD/YYYY HH:MM");
Ok(())
}