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
impl ReadOptions
pub fn new() -> Self
pub fn header_options(self, header: HeaderOptions) -> Self
pub fn header_row(self, row_index: u32) -> Self
pub fn header_span(self, span: u32) -> Self
pub fn max_rows(self, rows: u64) -> Self
Sourcepub fn with_images(self) -> Self
pub fn with_images(self) -> Self
打开图片读取(模型里声明了图片列时,只读这些列)
Sourcepub fn image_columns(self, cols: Vec<u16>) -> Self
pub fn image_columns(self, cols: Vec<u16>) -> Self
显式指定要读图的文件列
Sourcepub fn with_merges(self) -> Self
pub fn with_merges(self) -> Self
打开合并单元格读取:解析 <mergeCells> 并把左上角值回填到整个区域
代价是多扫一遍工作表 XML(见字段说明);不需要合并信息时保持默认即可。
Sourcepub fn without_merges(self) -> Self
pub fn without_merges(self) -> Self
关闭合并单元格读取
Sourcepub fn merges_exposed_only(self) -> Self
pub fn merges_exposed_only(self) -> Self
只暴露合并区域、不做值回填(会同时打开合并读取)
Sourcepub fn with_hyperlinks(self) -> Self
pub fn with_hyperlinks(self) -> Self
打开超链接读取(SheetStream::hyperlinks / ExcelReader::hyperlinks)
Sourcepub fn with_comments(self) -> Self
pub fn with_comments(self) -> Self
打开批注读取(SheetStream::comments / ExcelReader::comments)
Sourcepub fn with_validations(self) -> Self
pub fn with_validations(self) -> Self
打开数据验证读取(下拉 / 数值区间)
Sourcepub fn with_conditional_formats(self) -> Self
pub fn with_conditional_formats(self) -> Self
打开条件格式读取
Sourcepub fn computed<F>(self, def: ColumnDef, expr: F) -> Self
pub fn computed<F>(self, def: ColumnDef, expr: F) -> Self
追加一个导入计算列:文件里没有该列时,也能从本行其它列算出值
模型只需按同一个表头声明字段即可取到:
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)
});Sourcepub fn row_filter<F>(self, f: F) -> Self
pub fn row_filter<F>(self, f: F) -> Self
设置行过滤:返回 false 的行直接跳过(表尾“合计 / 备注“等脚注行)
use fast_excel::ReadOptions;
let options = ReadOptions::new().row_filter(|row| {
// 丢弃第一列为「合计」的汇总行
row.text_of("品名") != "合计"
});