You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
xlsxtocsv/src/xlsx_builder.rs

117 lines
3.4 KiB

use crate::{
arguments::{FillMergedCells, IncludeHidden, NumberRows, TrimSpaces},
xlsx::XlsxReader,
};
impl XlsxReader {
pub fn with_separator(mut self, separator: char) -> Self {
self.args.separator = separator;
self
}
pub fn with_replace_separator_by(mut self, replacement: String) -> Self {
self.args.replace_separator_by = Some(replacement);
self
}
pub fn with_include_hidden_columns(mut self, include: bool) -> Self {
self.args.include_hidden_columns = include;
self
}
pub fn with_include_hidden_rows(mut self, include: bool) -> Self {
self.args.include_hidden_rows = include;
self
}
pub fn with_include_hidden(mut self, include: IncludeHidden) -> Self {
let (col, row) = match include {
IncludeHidden::None => (false, false),
IncludeHidden::Rows => (false, true),
IncludeHidden::Columns => (true, false),
IncludeHidden::Both => (true, true),
};
self.args.include_hidden_columns = col;
self.args.include_hidden_rows = row;
self
}
pub fn with_fill_merged_cells_vertical(mut self, merge: bool) -> Self {
self.args.fill_merged_cells_vertical = merge;
self
}
pub fn with_fill_merged_cells_horizontal(mut self, merge: bool) -> Self {
self.args.fill_merged_cells_horizontal = merge;
self
}
pub fn with_fill_merged_cells(mut self, mode: FillMergedCells) -> Self {
let (horizontal, vertical) = match mode {
FillMergedCells::None => (false, false),
FillMergedCells::Horizontal => (true, false),
FillMergedCells::Vertical => (false, true),
FillMergedCells::Both => (true, true),
};
self.args.fill_merged_cells_horizontal = horizontal;
self.args.fill_merged_cells_vertical = vertical;
self
}
pub fn with_worksheet(mut self, worksheet_name: &str) -> Self {
self.args.worksheet = String::from(worksheet_name);
self
}
pub fn with_active_worksheet(mut self) -> Self {
self.args.active_worksheet = true;
self
}
pub fn with_trim_start(mut self) -> Self {
self.args.trim = match self.args.trim {
TrimSpaces::End => TrimSpaces::Both,
TrimSpaces::Start => TrimSpaces::Start,
TrimSpaces::Both => TrimSpaces::Both,
TrimSpaces::None => TrimSpaces::Start,
};
self
}
pub fn with_trim_end(mut self) -> Self {
self.args.trim = match self.args.trim {
TrimSpaces::End => TrimSpaces::End,
TrimSpaces::Start => TrimSpaces::Both,
TrimSpaces::Both => TrimSpaces::Both,
TrimSpaces::None => TrimSpaces::End,
};
self
}
pub fn with_trim(mut self, trim: TrimSpaces) -> Self {
self.args.trim = trim;
self
}
pub fn with_number_rows(mut self, number_rows: NumberRows) -> Self {
self.args.number_rows = number_rows;
self
}
pub fn with_skip_rows(mut self, skip: u32) -> Self {
self.args.skip_rows = skip;
self
}
pub fn with_end_of_line(mut self, eol: String) -> Self {
self.args.end_of_line = eol;
self
}
pub fn with_replace_end_of_line_by(mut self, replacement: String) -> Self {
self.args.replace_end_of_line_by = Some(replacement);
self
}
}