pub struct SheetOptions {
pub name: String,
pub columns: Vec<ColumnDef>,
pub write: WriteOptions,
pub computed: Vec<(ColumnDef, CellExpr)>,
pub transforms: Vec<(String, CellExpr)>,
}Expand description
单个工作表的配置
Fields§
§name: String§columns: Vec<ColumnDef>列定义(表头、别名、宽度、格式、图片列)
write: WriteOptions§computed: Vec<(ColumnDef, CellExpr)>计算列:导出时按表达式追加到末尾
transforms: Vec<(String, CellExpr)>列改写:按表头匹配,导出时用表达式替换该列的值
Implementations§
Source§impl SheetOptions
impl SheetOptions
pub fn new(name: impl Into<String>) -> Self
pub fn columns<I>(self, columns: I) -> Selfwhere
I: IntoIterator<Item = ColumnDef>,
pub fn write_options(self, write: WriteOptions) -> 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, SheetOptions, funcs};
let sheet = SheetOptions::new("明细")
.columns(ProductRow::columns())
.computed(ColumnDef::new("全名"), |row| {
CellValue::Text(funcs::concat(&[&row.text("姓"), &row.text("名")]))
});Sourcepub fn transform<F>(self, header: impl Into<String>, expr: F) -> Self
pub fn transform<F>(self, header: impl Into<String>, expr: F) -> Self
改写已有列的值(按表头匹配;表达式拿到的是本行其它列的原始值)
Sourcepub fn effective_columns(&self) -> Vec<ColumnDef>
pub fn effective_columns(&self) -> Vec<ColumnDef>
实际写出的列 = 基础列 + 追加的计算列
Trait Implementations§
Source§impl Clone for SheetOptions
impl Clone for SheetOptions
Source§impl Debug for SheetOptions
impl Debug for SheetOptions
Auto Trait Implementations§
impl !RefUnwindSafe for SheetOptions
impl !UnwindSafe for SheetOptions
impl Freeze for SheetOptions
impl Send for SheetOptions
impl Sync for SheetOptions
impl Unpin for SheetOptions
impl UnsafeUnpin for SheetOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more