get_num_from_ord

Function get_num_from_ord 

Source
pub fn get_num_from_ord(addr: &[u8]) -> Result<ColNum>
Expand description

Convert character based Excel cell column addresses to number. If you pass parameter D to this function, you will get 4

Examples found in repository?
examples/simple_batch_writer.rs (line 12)
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut writer = XlsxWriter::new();
8    let mut book = XlsxBook::new("xlsx/test.xlsx", true)?;
9    for shname in book.get_visible_sheets().clone() {
10        // left_ncol should not be 0
11        // each row will have 3 cells.
12        let mut sheet = book.get_sheet_by_name(&shname, 100, 0, 1, get_num_from_ord("C".as_bytes())?, true)?;
13
14        // the sheet name will be write at the begin of each row
15        let pre_cells = vec![shname];
16        if let Some((rows_nums, rows_data)) = sheet.get_remaining_cells()? {
17            // write all data
18            // writer.append_rows("sheet", rows_nums, rows_data, &pre_cells)?;
19            // if you don't want row numbers to be writed before data, set nrows = vec![];
20
21            // write by row
22            for (row_num, row_data) in rows_nums.into_iter().zip(rows_data) {
23                writer.append_row("sheet", Some(&row_num), row_data, &pre_cells)?;
24            }
25        }; 
26    };
27    writer.save_as("xlsx/out.xlsx")?;
28    Ok(())
29}
More examples
Hide additional examples
examples/merged_range.rs (line 8)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let mut book = XlsxBook::new("xlsx/test.xlsx", true)?;
5    for shname in book.get_visible_sheets().clone() {
6        // left_ncol should not be 0
7        // each row will have 3 cells.
8        let mut sheet = book.get_sheet_by_name(&shname, 100, 0, 1, get_num_from_ord("C".as_bytes())?, true)?;
9
10        // this is not necessary, if you don't care about the headers.
11        let (_, _header) = sheet.get_header_row()?;
12        if let Some((_rows_nums, _rows_data)) = sheet.get_remaining_cells()? {
13            //  some code
14        }; 
15
16        // should be called when all data have been scaned.
17        let merged_rngs = sheet.get_merged_ranges()?;
18        match is_merged_cell(merged_rngs, 2, get_num_from_ord("A".as_bytes())?) {
19            (true, None) => {
20                println!("a merged cell(not top left cell)");
21            },
22            (true, Some((nrow, ncol))) => {
23                println!("a merged cell(top left cell), taking {nrow} row(s) and {ncol} column(s)");
24            },
25            _ => {
26                println!("not a merged cell");
27            }
28        }
29    }
30    Ok(())
31}