cached_batch_reader/
cached_batch_reader.rs

1
2#[cfg(feature = "cached")]
3use xlsx_batch_reader::{get_ord_from_tuple, read::XlsxBook, MAX_COL_NUM};
4
5#[cfg(feature = "cached")]
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut book = XlsxBook::new("xlsx/test.xlsx", true)?;
8    for shname in book.get_visible_sheets().clone() {
9        // left_ncol should not be 0
10        // 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
11        let sheet = book.get_cached_sheet_by_name(&shname, 100, 0, 1, MAX_COL_NUM, false)?;
12
13        for (rows_nums, rows_data) in sheet {
14            // empty rows will be skiped
15            for (row, cells) in rows_nums.into_iter().zip(rows_data) {
16                for (col, cel) in cells.into_iter().enumerate() {
17                    let val: String = cel.get()?.unwrap();   // supprted types: String, i64, f64, bool, NaiveDate
18                    println!("the value of {} is {val}; raw cell is {:?}", get_ord_from_tuple(row, (col+1) as u16)?, cel);  
19                }
20            }
21        };
22    }
23    Ok(())
24}
25
26
27#[cfg(not(feature = "cached"))]
28fn main() {
29    println!("Please enable the feature 'cached' to run this example.");
30}