pub fn get_ord_from_tuple(row: RowNum, col: ColNum) -> Result<String>Expand description
Convert numbers based Excel cell addresses to characters. If you pass parameter (2, 4) to this function, you will get D2.
Examples found in repository?
examples/cached_batch_reader.rs (line 18)
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}More examples
examples/simple_batch_reader.rs (line 17)
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}examples/partial_batch_reader.rs (line 32)
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 mut sheet = book.get_sheet_by_name(&shname, 100, 0, 1, MAX_COL_NUM, true)?;
12
13 let mut skip_until = HashMap::new();
14 skip_until.insert("A".into(), "col1".into());
15 skip_until.insert("C".into(), "col3".into());
16 sheet.with_skip_until(&skip_until);
17 let mut read_before = HashMap::new();
18 read_before.insert("B".into(), "sum".into());
19 sheet.with_read_before(&read_before);
20 // only rows after skip_until-row(included) and before read_before(excluded) will be returned
21
22 let captures = vec!["B2".into(), "C1".into()].into_iter().collect();
23 sheet.with_capture_vals(captures);
24 println!("captures: {:?}", sheet.get_captured_vals());
25
26 for batch in sheet {
27 let (rows_nums, rows_data) = batch?;
28 // empty rows will be skiped
29 for (row, cells) in rows_nums.into_iter().zip(rows_data) {
30 for (col, cel) in cells.into_iter().enumerate() {
31 let val: String = cel.get()?.unwrap(); // supprted types: String, i64, f64, bool, NaiveDate
32 println!("the value of {} is {val}; raw cell is {:?}", get_ord_from_tuple(row, (col+1) as u16)?, cel);
33 }
34 }
35 // println!("captured values: {:?}", sheet.get_captured_vals());
36 };
37
38 }
39 Ok(())
40}