Skip to main content

ReadOptions

Struct ReadOptions 

Source
pub struct ReadOptions {
Show 14 fields pub header: HeaderOptions, pub max_rows: Option<u64>, pub skip_empty_rows: bool, pub read_images: bool, pub image_columns: Option<Vec<u16>>, pub read_merges: bool, pub fill_merged: bool, pub read_hyperlinks: bool, pub read_comments: bool, pub read_validations: bool, pub read_conditional_formats: bool, pub computed: Vec<ComputedColumn>, pub row_filter: Option<RowFilter>, pub trim_text: bool,
}
Expand description

读取选项

Fields§

§header: HeaderOptions

表头定位与匹配策略

§max_rows: Option<u64>

最多产出多少行(预览 / 抽样用)

§skip_empty_rows: bool

跳过整行空白

§read_images: bool

是否读取单元格内嵌图片

§image_columns: Option<Vec<u16>>

只读这些文件列(0 基)的图片;None = 按模型声明自动推导

§read_merges: bool

是否读取合并单元格信息(<mergeCells>)

开启后需要额外扫描一遍工作表 XML(<mergeCells> 在 <data> 之后, 流式读取无法边读边拿),因此默认关闭以保证百万行吞吐;需要时用 ReadOptions::with_merges 打开。

§fill_merged: bool

是否把合并区域左上角的值回填到区域内每个单元格(依赖 read_merges)

§read_hyperlinks: bool

是否读取超链接(<hyperlinks>,需额外扫一遍工作表 XML)

§read_comments: bool

是否读取批注(comments*.xml)

§read_validations: bool

是否读取数据验证(下拉 / 数值区间)

§read_conditional_formats: bool

是否读取条件格式

§computed: Vec<ComputedColumn>

导入计算列(文件里没有该列也能按表达式算出来)

§row_filter: Option<RowFilter>

行过滤:返回 false 的行会被跳过(表尾汇总行 / 脚注行)

§trim_text: bool

文本是否 trim

Implementations§

Source§

impl ReadOptions

Source

pub fn new() -> Self

Source

pub fn header_options(self, header: HeaderOptions) -> Self

Source

pub fn header_row(self, row_index: u32) -> Self

Source

pub fn header_span(self, span: u32) -> Self

Source

pub fn max_rows(self, rows: u64) -> Self

Source

pub fn with_images(self) -> Self

打开图片读取(模型里声明了图片列时,只读这些列)

Source

pub fn image_columns(self, cols: Vec<u16>) -> Self

显式指定要读图的文件列

Source

pub fn with_merges(self) -> Self

打开合并单元格读取:解析 <mergeCells> 并把左上角值回填到整个区域

代价是多扫一遍工作表 XML(见字段说明);不需要合并信息时保持默认即可。

Source

pub fn without_merges(self) -> Self

关闭合并单元格读取

Source

pub fn merges_exposed_only(self) -> Self

只暴露合并区域、不做值回填(会同时打开合并读取)

打开超链接读取(SheetStream::hyperlinks / ExcelReader::hyperlinks)

Source

pub fn with_comments(self) -> Self

打开批注读取(SheetStream::comments / ExcelReader::comments)

Source

pub fn with_validations(self) -> Self

打开数据验证读取(下拉 / 数值区间)

Source

pub fn with_conditional_formats(self) -> Self

打开条件格式读取

Source

pub fn computed<F>(self, def: ColumnDef, expr: F) -> Self
where F: for<'a> Fn(&RowData<'a>) -> CellValue + Send + Sync + 'static,

追加一个导入计算列:文件里没有该列时,也能从本行其它列算出值

模型只需按同一个表头声明字段即可取到:

ⓘ
use fast_excel::{CellValue, ColumnDef, ReadOptions};
let options = ReadOptions::new().computed(ColumnDef::new("全名"), |row| {
    let full = format!("{}{}", row.text_of("姓"), row.text_of("名"));
    CellValue::Text(full)
});
Source

pub fn row_filter<F>(self, f: F) -> Self
where F: for<'a> Fn(&RowData<'a>) -> bool + Send + Sync + 'static,

设置行过滤:返回 false 的行直接跳过(表尾“合计 / 备注“等脚注行)

ⓘ
use fast_excel::ReadOptions;
let options = ReadOptions::new().row_filter(|row| {
    // 丢弃第一列为「合计」的汇总行
    row.text_of("品名") != "合计"
});
Source

pub fn skip_empty_rows(self, skip: bool) -> Self

Source

pub fn trim_text(self, trim: bool) -> Self

Trait Implementations§

Source§

impl Clone for ReadOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ReadOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ReadOptions

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.