Skip to main content

Reader

Trait Reader 

Source
pub trait Reader<RS>: Sized
where RS: Read + Seek,
{ type Error: Debug + From<Error>;
Show 14 methods // Required methods fn new(reader: RS) -> Result<Self, Self::Error>; fn with_header_row(&mut self, header_row: HeaderRow) -> &mut Self; fn vba_project(&mut self) -> Result<Option<VbaProject>, Self::Error>; fn metadata(&self) -> &Metadata; fn worksheet_range( &mut self, name: &str, ) -> Result<Range<Data>, Self::Error>; fn worksheets(&mut self) -> Vec<(String, Range<Data>)>; fn worksheet_formula( &mut self, _: &str, ) -> Result<Range<String>, Self::Error>; fn worksheet_style(&mut self, name: &str) -> Result<StyleRange, Self::Error>; fn worksheet_layout( &mut self, name: &str, ) -> Result<WorksheetLayout, Self::Error>; fn pictures(&self) -> Option<Vec<(String, Vec<u8>)>>; // Provided methods fn sheet_names(&self) -> Vec<String> { ... } fn sheets_metadata(&self) -> &[Sheet] { ... } fn defined_names(&self) -> &[(String, String)] { ... } fn worksheet_range_at( &mut self, n: usize, ) -> Option<Result<Range<Data>, Self::Error>> { ... }
}
Expand description

A trait to share spreadsheets reader functions across different FileTypes

Required Associated Types§

Source

type Error: Debug + From<Error>

Error specific to file type

Required Methods§

Source

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

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>, Self::Error>

Gets VbaProject

Source

fn metadata(&self) -> &Metadata

Initialize

Source

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

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, _: &str) -> Result<Range<String>, Self::Error>

Read worksheet formula in corresponding worksheet path

Source

fn worksheet_style(&mut self, name: &str) -> Result<StyleRange, Self::Error>

Read worksheet styles as an RLE-compressed StyleRange.

Returns a StyleRange containing styles for all cells with explicit formatting. The styles are stored in run-length encoded format for memory efficiency.

Source

fn worksheet_layout( &mut self, name: &str, ) -> Result<WorksheetLayout, Self::Error>

Read worksheet layout information (column widths and row heights)

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.

Returns a vector of tuples containing the file extension and a buffer of the image data.

§Examples

An example of getting the raw data of pictures in an spreadsheet file.

    // Open the workbook.
    let workbook: Xlsx<_> = open_workbook(path)?;

    // Get the data for each picture.
    if let Some(pics) = workbook.pictures() {
        for (ext, data) in pics {
            println!("Type: '{}', Size: {} bytes", ext, data.len());
        }
    }

Output:

Type: 'jpg', Size: 20762 bytes
Type: 'png', Size: 23453 bytes

Provided Methods§

Source

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

Get all sheet names of this workbook, in workbook order

§Examples
use calamine::{Xlsx, open_workbook, Reader};

let mut workbook: Xlsx<_> = open_workbook(path).unwrap();
println!("Sheets: {:#?}", workbook.sheet_names());
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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<RS> Reader<RS> for Sheets<RS>
where RS: Read + Seek,

Source§

impl<RS> Reader<RS> for Ods<RS>
where RS: Read + Seek,

Source§

impl<RS: Read + Seek> Reader<RS> for Xls<RS>

Source§

impl<RS: Read + Seek> Reader<RS> for Xlsb<RS>

Source§

impl<RS: Read + Seek> Reader<RS> for Xlsx<RS>