diff --git a/noms.xlsx b/noms.xlsx index ca4f225..a0333bd 100644 Binary files a/noms.xlsx and b/noms.xlsx differ diff --git a/src/arguments.rs b/src/arguments.rs index bfd657f..fb8c183 100644 --- a/src/arguments.rs +++ b/src/arguments.rs @@ -122,6 +122,12 @@ pub(crate) struct RawArguments { /// avoid nth first rows of xlsx file #[arg(short = 'k', long, default_value_t = 0)] pub skip_rows: u32, + /// avoid empty lines + #[arg(short, long, default_value_t = false)] + pub avoid_empty_rows: bool, + /// consider first line (after row skipped) as header line + #[arg(short, long, default_value_t = false)] + pub header: bool, /// change end of line character #[arg(short, long, default_value_t = String::from("\n"))] pub end_of_line: String, @@ -160,6 +166,10 @@ pub struct Arguments { pub(crate) number_rows: NumberRows, /// Avoid nth first rows of xlsx file pub(crate) skip_rows: u32, + /// avoid empty lines + pub avoid_empty_rows: bool, + /// first line (after row skipped) is header line + pub header: bool, ///# csv output specific options /// Separator for output pub(crate) separator: char, @@ -194,6 +204,8 @@ impl Default for Arguments { trim: Default::default(), number_rows: Default::default(), skip_rows: Default::default(), + avoid_empty_rows: false, + header: false, end_of_line: String::from("\n"), replace_end_of_line_by: Default::default(), } @@ -231,6 +243,8 @@ impl From for Arguments { trim: raw.trim, number_rows: raw.number_rows, skip_rows: raw.skip_rows, + avoid_empty_rows: raw.avoid_empty_rows, + header: raw.header, end_of_line: raw.end_of_line, replace_end_of_line_by: raw.replace_end_of_line_by, } diff --git a/src/main.rs b/src/main.rs index d978d34..2536763 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ pub use xlsxtocsv::{error::Error, xlsx::XlsxReader}; fn main() -> Result<(), Error> { let lf = XlsxReader::new("noms.xlsx") .with_active_worksheet() + .with_fill_merged_cells(xlsxtocsv::arguments::FillMergedCells::Both) .to_lazyframe()?; let df = lf.collect()?; diff --git a/src/xlsx.rs b/src/xlsx.rs index 9baf3ea..f3346af 100644 --- a/src/xlsx.rs +++ b/src/xlsx.rs @@ -13,9 +13,11 @@ pub struct XlsxReader { pub(crate) book: Option, pub(crate) sheet_index: Option, pub(crate) worksheet_dimensions: RefCell>, + pub(crate) current_row: u32, } impl XlsxReader { + /// Create an XlsxReader from a path or clap arguments pub fn new(args: impl IntoArgs) -> Self { let args = args.into_args(); @@ -24,6 +26,7 @@ impl XlsxReader { book: None, sheet_index: None, worksheet_dimensions: RefCell::new(None), + current_row: 0u32, } } @@ -91,7 +94,6 @@ impl XlsxReader { let mut num_cols = 0; let mut num_rows = 0; let sheet = self.get_sheet().unwrap(); - for cell in sheet.get_cell_collection() { let value = get_value(cell); //.get_formatted_value(); @@ -127,13 +129,23 @@ impl XlsxReader { let value = cell.get_formatted_value(); let coord = cell.get_coordinate(); let col = *coord.get_col_num() - 1; - res[col as usize] = value; + if col < num_cols.try_into().unwrap() { + res[col as usize] = value; + } } res } } +impl Iterator for XlsxReader { + type Item = Result; + + fn next(&mut self) -> Option { + todo!() + } +} + pub fn list_worksheets(book: Spreadsheet) -> Result, Error> { let sheets = book.get_sheet_collection(); let mut res = vec![]; diff --git a/src/xlsx_builder.rs b/src/xlsx_builder.rs index c8f55ca..9713c50 100644 --- a/src/xlsx_builder.rs +++ b/src/xlsx_builder.rs @@ -104,6 +104,16 @@ impl XlsxReader { self } + pub fn with_avoid_empty_rows(mut self) -> Self { + self.args.avoid_empty_rows = true; + self + } + + pub fn with_header(mut self) -> Self { + self.args.header = true; + self + } + pub fn with_end_of_line(mut self, eol: String) -> Self { self.args.end_of_line = eol; self