pub fn is_merged_cell(
mgs: &Vec<MergedRange>,
row: RowNum,
col: ColNum,
) -> (bool, Option<(RowNum, ColNum)>)Expand description
check whether the cell is a merged cell. If it is the first cell in the merged area, return the size of the merged area. RowNum and ColNum start from 1.
Examples found in repository?
examples/merged_range.rs (line 18)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut book = XlsxBook::new("xlsx/test.xlsx", true)?;
for shname in book.get_visible_sheets().clone() {
// left_ncol should not be 0
// each row will have 3 cells.
let mut sheet = book.get_sheet_by_name(&shname, 100, 0, 1, get_num_from_ord("C".as_bytes())?, true)?;
// this is not necessary, if you don't care about the headers.
let (_, _header) = sheet.get_header_row()?;
if let Some((_rows_nums, _rows_data)) = sheet.get_remaining_cells()? {
// some code
};
// should be called when all data have been scaned.
let merged_rngs = sheet.get_merged_ranges()?;
match is_merged_cell(merged_rngs, 2, get_num_from_ord("A".as_bytes())?) {
(true, None) => {
println!("a merged cell(not top left cell)");
},
(true, Some((nrow, ncol))) => {
println!("a merged cell(top left cell), taking {nrow} row(s) and {ncol} column(s)");
},
_ => {
println!("not a merged cell");
}
}
}
Ok(())
}