Struct calamine::Range [] [src]

pub struct Range { /* fields omitted */ }

A struct which represents a squared selection of cells

Methods

impl Range
[src]

Creates a new Range

When possible, prefer the more efficient Range::from_sparse

Creates a Range from a coo sparse vector of Cells.

Coordinate list (COO) is the natural way cells are stored in excel files Inner size is defined only by non empty.

cells: Vec of non empty Cells, sorted by row

Panics

panics when a Cell row is lower than the first Cell row or bigger than the last Cell row.

Examples

use calamine::{Range, DataType, Cell};

let v = vec![Cell::new((1, 200), DataType::Float(1.)),
             Cell::new((55, 2),  DataType::String("a".to_string()))];
let range = Range::from_sparse(v);

assert_eq!(range.get_size(), (55, 199));

Get top left cell position (row, column)

Get bottom right cell position (row, column)

Get column width

Get column width

Get size

Is range empty

Set inner value

Will try to resize inner structure if the value is out of bounds.

Try to avoid this method as much as possible and prefer initializing the Range with from_sparce constructor.

Examples

use calamine::{Range, DataType};

let mut range = Range::new((0, 0), (5, 2));
assert_eq!(range.get_value((2, 1)), &DataType::Empty);
range.set_value((2, 1), DataType::Float(1.0))
    .expect("Cannot set value at position (2, 1)");
assert_eq!(range.get_value((2, 1)), &DataType::Float(1.0));

Get cell value

Panics if indexes are out of range bounds

Get an iterator over inner rows

Examples

use calamine::Range;

let range = Range::new((0, 0), (5, 2));
// with rows item row: &[DataType]
assert_eq!(range.rows().map(|r| r.len()).sum::<usize>(), 18);

Get an iterator over used cells only

This can be much faster than iterating rows as Range is saved as a sparce matrix

Trait Implementations

impl Debug for Range
[src]

Formats the value using the given formatter.

impl Default for Range
[src]

Returns the "default value" for a type. Read more

impl Clone for Range
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more