pub struct Xls<RS> { /* private fields */ }Expand description
A struct representing an old xls format file (CFB)
Implementations§
Source§impl<RS: Read + Seek> Xls<RS>
impl<RS: Read + Seek> Xls<RS>
Sourcepub fn new_with_options(
reader: RS,
options: XlsOptions,
) -> Result<Self, XlsError>
pub fn new_with_options( reader: RS, options: XlsOptions, ) -> Result<Self, XlsError>
Creates a new instance using Options to inform parsing.
use calamine::{Xls,XlsOptions};
let mut options = XlsOptions::default();
// ...set options...
let workbook = Xls::new_with_options(reader, options)?;Sourcepub fn merge_cells_by_sheet_name(
&self,
name: &str,
) -> Result<Vec<Dimensions>, XlsError>
pub fn merge_cells_by_sheet_name( &self, name: &str, ) -> Result<Vec<Dimensions>, XlsError>
Get the merged cells/regions in a worksheet by sheet name.
Merged cells in Excel are a range of cells that have been merged to act as a single cell. It is often used to create headers or titles that span multiple columns or rows.
The function returns a vector of Dimensions for the merged cells in
the named worksheet.
Note: unlike the equivalent crate::Xlsx method, this method takes
&self because XLS data is fully parsed at construction time and held
in memory.
§Parameters
name: The name of the worksheet.
§Errors
XlsError::WorksheetNotFoundif no worksheet with the given name exists.
§Examples
use calamine::{open_workbook, Error, Reader, Xls};
fn main() -> Result<(), Error> {
let path = "tests/merge_cells.xls";
// Open the workbook.
let workbook: Xls<_> = open_workbook(path)?;
// Get the names of all the sheets in the workbook.
let sheet_names = workbook.sheet_names();
for sheet_name in &sheet_names {
println!("{sheet_name}:");
// Get the merged cells in the current sheet.
let merge_cells = workbook.merge_cells_by_sheet_name(sheet_name)?;
// Print the dimensions of each merged region.
for dimension in &merge_cells {
println!(" {dimension:?}");
}
}
Ok(())
}Output:
Dimensions { start: (0, 0), end: (0, 1) }
Dimensions { start: (1, 0), end: (3, 0) }
Dimensions { start: (1, 1), end: (3, 3) }Sourcepub fn merge_cells_by_sheet_id(
&self,
id: usize,
) -> Result<Vec<Dimensions>, XlsError>
pub fn merge_cells_by_sheet_id( &self, id: usize, ) -> Result<Vec<Dimensions>, XlsError>
Get the merged cells/regions in a worksheet by sheet index.
Merged cells in Excel are a range of cells that have been merged to act as a single cell. It is often used to create headers or titles that span multiple columns or rows.
The function returns a vector of Dimensions for the merged cells in
the worksheet at the given index.
Note: unlike the equivalent crate::Xlsx method, this method takes
&self because XLS data is fully parsed at construction time and held
in memory.
§Parameters
id: The zero-based index of the worksheet.
§Errors
XlsError::WorksheetNotFoundifidis out of range.
§Examples
use calamine::{open_workbook, Error, Xls};
fn main() -> Result<(), Error> {
let path = "tests/merge_cells.xls";
// Open the workbook.
let workbook: Xls<_> = open_workbook(path)?;
// Get the merged cells in the first worksheet.
let merge_cells = workbook.merge_cells_by_sheet_id(0)?;
// Print the dimensions of each merged region.
for dimension in &merge_cells {
println!("{dimension:?}");
}
Ok(())
}Output:
Dimensions { start: (0, 0), end: (0, 1) }
Dimensions { start: (1, 0), end: (3, 0) }
Dimensions { start: (1, 1), end: (3, 3) }Sourcepub fn has_1904_epoch(&self) -> bool
pub fn has_1904_epoch(&self) -> bool
Check if the workbook uses the 1904 date system.
Returns true if the workbook uses the 1904 date epoch (used by some older
Mac versions of Excel), or false if it uses the standard 1900 date epoch.
§Examples
use calamine::{open_workbook, Error, Xls};
fn main() -> Result<(), Error> {
let workbook: Xls<_> = open_workbook("tests/date_1904.xls")?;
let is_1904 = workbook.has_1904_epoch();
println!("Uses 1904 date system: {}", is_1904);
Ok(())
}Trait Implementations§
Source§impl<RS: Read + Seek> Reader<RS> for Xls<RS>
impl<RS: Read + Seek> Reader<RS> for Xls<RS>
Source§fn metadata(&self) -> &Metadata
fn metadata(&self) -> &Metadata
Parses Workbook stream, no need for the relationships variable
Source§fn with_header_row(&mut self, header_row: HeaderRow) -> &mut Self
fn with_header_row(&mut self, header_row: HeaderRow) -> &mut Self
header_row is None, the first non-empty row will be used as header rowSource§fn vba_project(&mut self) -> Result<Option<VbaProject>, XlsError>
fn vba_project(&mut self) -> Result<Option<VbaProject>, XlsError>
VbaProjectSource§fn worksheet_range(&mut self, name: &str) -> Result<Range<Data>, XlsError>
fn worksheet_range(&mut self, name: &str) -> Result<Range<Data>, XlsError>
Source§fn worksheet_formula(&mut self, name: &str) -> Result<Range<String>, XlsError>
fn worksheet_formula(&mut self, name: &str) -> Result<Range<String>, XlsError>
Source§fn pictures(&self) -> Option<Vec<(String, Vec<u8>)>>
fn pictures(&self) -> Option<Vec<(String, Vec<u8>)>>
picture only.