parent
3f1feea6cf
commit
9dd247b20c
@ -0,0 +1 @@
|
||||
,sanchezn,pc-sanchezn,17.02.2026 15:16,/home/sanchezn/.local/share/onlyoffice;
|
||||
Binary file not shown.
@ -1,3 +1,7 @@
|
||||
pub mod arguments;
|
||||
pub mod error;
|
||||
pub mod xlsx;
|
||||
pub mod xlsx_builder;
|
||||
|
||||
//#[cfg(feature = "csv")]
|
||||
pub mod xlsx_to_csv;
|
||||
|
||||
@ -1,8 +1,14 @@
|
||||
use xlsxtocsv::{arguments::Arguments, xlsx::xlsxtocsv};
|
||||
use xlsxtocsv::{arguments::Arguments, xlsx::XlsxReader};
|
||||
|
||||
fn main() {
|
||||
let args = Arguments::parse();
|
||||
if let Err(error) = xlsxtocsv(&args) {
|
||||
eprintln!("{}", error);
|
||||
/* if let Err(error) = xlsxtocsv(&args) {
|
||||
eprintln!("{}", error);
|
||||
}*/
|
||||
|
||||
let xlsxreader = XlsxReader::new(args).unwrap();
|
||||
let reader = xlsxreader.to_csv();
|
||||
for line in reader {
|
||||
println!("{line}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,113 @@
|
||||
use crate::{
|
||||
arguments::{FillMergedCells, IncludeHidden, NumberRows, TrimSpaces},
|
||||
error::Error,
|
||||
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) -> Result<Self, Error> {
|
||||
self.args.worksheet = String::from(worksheet_name);
|
||||
|
||||
self.sheet_index = Self::get_worksheet_index(&self.book, worksheet_name)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn with_active_worksheet(mut self, active_worksheet: bool) -> Self {
|
||||
self.args.active_worksheet = active_worksheet;
|
||||
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_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
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
use crate::xlsx::XlsxReader;
|
||||
|
||||
pub struct XlsxToCsvLines<'a> {
|
||||
xlsx_reader: &'a XlsxReader,
|
||||
current_row: u32,
|
||||
num_rows: u32,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for XlsxToCsvLines<'a> {
|
||||
type Item = String;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.current_row > self.num_rows {
|
||||
return None;
|
||||
}
|
||||
|
||||
let row = self.xlsx_reader.get_row(self.current_row);
|
||||
self.current_row += 1;
|
||||
|
||||
let row = row.join(";");
|
||||
|
||||
Some(row)
|
||||
}
|
||||
}
|
||||
|
||||
impl XlsxReader {
|
||||
pub fn to_csv(&self) -> XlsxToCsvLines<'_> {
|
||||
let num_rows = self.get_worksheet_dimensions().1;
|
||||
XlsxToCsvLines {
|
||||
xlsx_reader: self,
|
||||
current_row: 0,
|
||||
num_rows,
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue