use thiserror::Error;
pub type Result<T> = std::result::Result<T, ExcelError>;
#[derive(Error, Debug)]
pub enum ExcelError {
#[error("Failed to read Excel file: {0}")]
ReadError(String),
#[error("Failed to write Excel file: {0}")]
WriteError(String),
#[error("Sheet '{sheet}' not found. Available sheets: {available}")]
SheetNotFound { sheet: String, available: String },
#[error("Failed to write row {row} to sheet '{sheet}': {source}")]
WriteRowError {
row: u32,
sheet: String,
#[source]
source: Box<ExcelError>,
},
#[error("Invalid cell reference: {0}")]
InvalidCell(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
#[error("Calamine error: {0}")]
CaliamineError(String),
#[error("Invalid format: {0}")]
InvalidFormat(String),
#[error("Feature not supported: {0}")]
NotSupported(String),
}
impl From<calamine::Error> for ExcelError {
fn from(err: calamine::Error) -> Self {
ExcelError::CaliamineError(err.to_string())
}
}
impl From<calamine::XlsxError> for ExcelError {
fn from(err: calamine::XlsxError) -> Self {
ExcelError::CaliamineError(err.to_string())
}
}
impl From<calamine::XlsError> for ExcelError {
fn from(err: calamine::XlsError) -> Self {
ExcelError::CaliamineError(err.to_string())
}
}
impl From<zip::result::ZipError> for ExcelError {
fn from(err: zip::result::ZipError) -> Self {
ExcelError::WriteError(err.to_string())
}
}