Skip to main content

Xls

Struct Xls 

Source
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>

Source

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)?;
Source

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
§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) }
Source

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
§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) }
Source

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>

Source§

fn metadata(&self) -> &Metadata

Parses Workbook stream, no need for the relationships variable

Source§

type Error = XlsError

Error specific to file type
Source§

fn new(reader: RS) -> Result<Self, XlsError>

Creates a new instance.
Source§

fn with_header_row(&mut self, header_row: HeaderRow) -> &mut Self

Set header row (i.e. first row to be read) If header_row is None, the first non-empty row will be used as header row
Source§

fn vba_project(&mut self) -> Result<Option<VbaProject>, XlsError>

Gets VbaProject
Source§

fn worksheet_range(&mut self, name: &str) -> Result<Range<Data>, XlsError>

Read worksheet data in corresponding worksheet path
Source§

fn worksheets(&mut self) -> Vec<(String, Range<Data>)>

Fetch all worksheet data & paths
Source§

fn worksheet_formula(&mut self, name: &str) -> Result<Range<String>, XlsError>

Read worksheet formula in corresponding worksheet path
Source§

fn pictures(&self) -> Option<Vec<(String, Vec<u8>)>>

Available on crate feature picture only.
Get the raw data of the pictures in a workbook. Read more
Source§

fn sheet_names(&self) -> Vec<String>

Get all sheet names of this workbook, in workbook order Read more
Source§

fn sheets_metadata(&self) -> &[Sheet]

Fetch all sheets metadata
Source§

fn defined_names(&self) -> &[(String, String)]

Get all defined names (Ranges names etc)
Source§

fn worksheet_range_at( &mut self, n: usize, ) -> Option<Result<Range<Data>, Self::Error>>

Get the nth worksheet. Shortcut for getting the nth worksheet name, then the corresponding worksheet.
Source§

fn pictures_with_metadata(&self) -> Vec<Picture>

Available on crate feature picture only.
Get workbook picture/image metadata. Read more

Auto Trait Implementations§

§

impl<RS> Freeze for Xls<RS>
where RS: Freeze,

§

impl<RS> RefUnwindSafe for Xls<RS>
where RS: RefUnwindSafe,

§

impl<RS> Send for Xls<RS>
where RS: Send,

§

impl<RS> Sync for Xls<RS>
where RS: Sync,

§

impl<RS> Unpin for Xls<RS>
where RS: Unpin,

§

impl<RS> UnsafeUnpin for Xls<RS>
where RS: UnsafeUnpin,

§

impl<RS> UnwindSafe for Xls<RS>
where RS: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.