pub enum CellValue<'a> {
Blank,
Bool(bool),
Number(f64),
Date(f64),
Time(f64),
Datetime(f64),
Shared(&'a String),
String(String),
Error(String),
}Expand description
Cell Value Type
Variants§
Implementations§
Source§impl<'a> CellValue<'a>
impl<'a> CellValue<'a>
Sourcepub fn get<T: FromCellValue>(&'a self) -> Result<Option<T>>
pub fn get<T: FromCellValue>(&'a self) -> Result<Option<T>>
Attention: as to blank cell, String will return String::new(), and other types will return None.
Examples found in repository?
examples/read_datatime.rs (line 13)
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 mut sheet = book.get_sheet_by_name(&shname, 100, 3, 1, MAX_COL_NUM, false)?;
10
11 if let Some((_, rows_data)) = sheet.get_remaining_cells()? {
12 let row = &rows_data[0];
13 let val_dt: NaiveDate = row[0].get()?.unwrap();
14 let val_tm: NaiveTime = row[0].get()?.unwrap();
15 let val_dttm: NaiveDateTime = row[0].get()?.unwrap();
16 let val_stamp: Timestamp = row[0].get()?.unwrap(); // since v0.1.4
17 println!("date:{}\ntime:{}\ndatetime:{}\ntimestamp:{}", val_dt, val_tm, val_dttm, val_stamp.utc());
18 };
19 }
20 Ok(())
21}More examples
examples/cached_batch_reader.rs (line 17)
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}examples/simple_batch_reader.rs (line 16)
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 31)
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}Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for CellValue<'a>
impl<'a> RefUnwindSafe for CellValue<'a>
impl<'a> Send for CellValue<'a>
impl<'a> Sync for CellValue<'a>
impl<'a> Unpin for CellValue<'a>
impl<'a> UnwindSafe for CellValue<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more