simple_batch_reader/
simple_batch_reader.rs

1
2use xlsx_batch_reader::{get_ord_from_tuple, read::XlsxBook, MAX_COL_NUM};
3
4fn main() -> Result<(), Box<dyn std::error::Error>> {
5    let mut book = XlsxBook::new("xlsx/test.xlsx", true)?;
6    for shname in book.get_visible_sheets().clone() {
7        // left_ncol should not be 0
8        // the tail empty cells will be ignored, if you want the length of cells in each row is fixed, you can set right_ncol to a number not MAX_COL_NUM
9        let sheet = book.get_sheet_by_name(&shname, 100, 0, 1, MAX_COL_NUM, false)?;
10
11        for batch in sheet {
12            let (rows_nums, rows_data) = batch?;
13            // empty rows will be skiped
14            for (row, cells) in rows_nums.into_iter().zip(rows_data) {
15                for (col, cel) in cells.into_iter().enumerate() {
16                    let val: String = cel.get()?.unwrap();   // supprted types: String, i64, f64, bool, NaiveDate
17                    println!("the value of {} is {val}; raw cell is {:?}", get_ord_from_tuple(row, (col+1) as u16)?, cel);  
18                }
19            }
20        };
21    }
22    Ok(())
23}