modification du trim

pull/3/head
Nicolas Sanchez 2 months ago
parent d357aedc85
commit 6f2933c6f3

@ -19,6 +19,26 @@ impl ToString for FillMergedCells {
}
}
#[derive(Clone, Debug, ValueEnum)]
pub enum TrimSpaces {
End,
Start,
Both,
None
}
impl ToString for TrimSpaces {
fn to_string(&self) -> String {
match self {
TrimSpaces::End => "end".into(),
TrimSpaces::Start => "start".into(),
TrimSpaces::Both => "both".into(),
TrimSpaces::None => "none".into(),
}
}
}
#[derive(Parser, Debug)]
pub struct Arguments {
/// Path to the xlsx file
@ -40,6 +60,6 @@ pub struct Arguments {
#[arg(short, long, default_value_t = String::from("0"))]
pub worksheet: String,
/// Trim white spaces at end of cells
#[arg(short, long, default_value_t = false)]
pub trim_end: bool,
#[arg(short, long, default_value_t = TrimSpaces::None)]
pub trim: TrimSpaces,
}

@ -1,7 +1,7 @@
use std::path::Path;
use umya_spreadsheet::{Range, Worksheet, reader};
use crate::arguments::Arguments;
use crate::arguments::{Arguments, TrimSpaces};
use crate::error::Error;
pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
@ -85,9 +85,12 @@ pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
}
// apply modifications to cells value (trim spaces, replace separator chars, line breaks etc.)
if args.trim_end {
value = String::from(value.trim_end());
}
value = match args.trim {
TrimSpaces::End => String::from(value.trim_end()),
TrimSpaces::Start => String::from(value.trim_start()),
TrimSpaces::Both => String::from(value.trim()),
TrimSpaces::None => value,
};
value = value.replace('\r', "").replace('\n', " ");
if let Some(ref replacement) = args.replace_separator_by {
value = value.replace(args.separator, replacement);

Loading…
Cancel
Save