ajout de clap

pull/3/head
Nicolas Sanchez 2 months ago
parent e5db01c4b9
commit 2ecb864c6e

281
Cargo.lock generated

@ -51,21 +51,62 @@ dependencies = [
] ]
[[package]] [[package]]
name = "arbitrary" name = "anstream"
version = "1.4.2" version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1" checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
dependencies = [ dependencies = [
"derive_arbitrary", "anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
[[package]]
name = "anstyle-parse"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
dependencies = [
"anstyle",
"once_cell_polyfill",
"windows-sys",
] ]
[[package]] [[package]]
name = "atoi_simd" name = "arbitrary"
version = "0.16.1" version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a49e05797ca52e312a0c658938b7d00693ef037799ef7187678f212d7684cf" checksum = "c3d036a3c4ab069c7b410a2ce876bd74808d2d0888a82667669f8e783a898bf1"
dependencies = [ dependencies = [
"debug_unsafe", "derive_arbitrary",
] ]
[[package]] [[package]]
@ -125,23 +166,6 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "calamine"
version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da56b262e8a827c6b12c3dde4ea4622e0ff542bd2e9ea5855e4cb523481d77b7"
dependencies = [
"atoi_simd",
"byteorder",
"codepage",
"encoding_rs",
"fast-float2",
"log",
"quick-xml 0.38.3",
"serde",
"zip 4.6.1",
]
[[package]] [[package]]
name = "cbc" name = "cbc"
version = "0.1.2" version = "0.1.2"
@ -200,14 +224,51 @@ dependencies = [
] ]
[[package]] [[package]]
name = "codepage" name = "clap"
version = "0.1.2" version = "4.5.48"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48f68d061bc2828ae826206326e61251aca94c1e4a5305cf52d9138639c918b4" checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae"
dependencies = [ dependencies = [
"encoding_rs", "clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.5.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
] ]
[[package]]
name = "clap_lex"
version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675"
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]] [[package]]
name = "core-foundation-sys" name = "core-foundation-sys"
version = "0.8.7" version = "0.8.7"
@ -248,12 +309,6 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "debug_unsafe"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85d3cef41d236720ed453e102153a53e4cc3d2fde848c0078a50cf249e8e3e5b"
[[package]] [[package]]
name = "derive_arbitrary" name = "derive_arbitrary"
version = "1.4.2" version = "1.4.2"
@ -319,12 +374,6 @@ dependencies = [
"regex-syntax", "regex-syntax",
] ]
[[package]]
name = "fast-float2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8eb564c5c7423d25c886fb561d1e4ee69f72354d16918afa32c08811f6b6a55"
[[package]] [[package]]
name = "find-msvc-tools" name = "find-msvc-tools"
version = "0.1.2" version = "0.1.2"
@ -338,7 +387,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d" checksum = "4a3d7db9596fecd151c5f638c0ee5d5bd487b6e0ea232e5dc96d5250f6f94b1d"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"libz-rs-sys",
"miniz_oxide", "miniz_oxide",
] ]
@ -387,6 +435,12 @@ version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]] [[package]]
name = "hmac" name = "hmac"
version = "0.12.1" version = "0.12.1"
@ -461,6 +515,12 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.15" version = "1.0.15"
@ -489,15 +549,6 @@ version = "0.2.176"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174" checksum = "58f929b4d672ea937a23a1ab494143d968337a5f47e56d0815df1e0890ddf174"
[[package]]
name = "libz-rs-sys"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "840db8cf39d9ec4dd794376f38acc40d0fc65eec2a8f484f7fd375b84602becd"
dependencies = [
"zlib-rs",
]
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.28" version = "0.4.28"
@ -544,6 +595,12 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "once_cell_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad"
[[package]] [[package]]
name = "pest" name = "pest"
version = "2.8.2" version = "2.8.2"
@ -607,16 +664,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "quick-xml"
version = "0.38.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89"
dependencies = [
"encoding_rs",
"memchr",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.41" version = "1.0.41"
@ -739,6 +786,12 @@ version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.6.1" version = "2.6.1"
@ -841,12 +894,12 @@ dependencies = [
"imagesize", "imagesize",
"lazy_static", "lazy_static",
"md-5", "md-5",
"quick-xml 0.37.5", "quick-xml",
"regex", "regex",
"sha2", "sha2",
"thin-vec", "thin-vec",
"thousands", "thousands",
"zip 2.4.2", "zip",
] ]
[[package]] [[package]]
@ -855,6 +908,12 @@ version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "1.18.1" version = "1.18.1"
@ -1013,6 +1072,80 @@ dependencies = [
"windows-link", "windows-link",
] ]
[[package]]
name = "windows-sys"
version = "0.60.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.53.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d42b7b7f66d2a06854650af09cfdf8713e427a439c97ad65a6375318033ac4b"
dependencies = [
"windows-link",
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
[[package]]
name = "windows_aarch64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
[[package]]
name = "windows_i686_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
[[package]]
name = "windows_i686_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
[[package]]
name = "windows_i686_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
[[package]]
name = "windows_x86_64_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
[[package]]
name = "windows_x86_64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
[[package]] [[package]]
name = "wit-bindgen" name = "wit-bindgen"
version = "0.46.0" version = "0.46.0"
@ -1023,7 +1156,7 @@ checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
name = "xlsxtocsv" name = "xlsxtocsv"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"calamine", "clap",
"umya-spreadsheet", "umya-spreadsheet",
] ]
@ -1064,26 +1197,6 @@ dependencies = [
"zopfli", "zopfli",
] ]
[[package]]
name = "zip"
version = "4.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caa8cd6af31c3b31c6631b8f483848b91589021b28fffe50adada48d4f4d2ed1"
dependencies = [
"arbitrary",
"crc32fast",
"flate2",
"indexmap",
"memchr",
"zopfli",
]
[[package]]
name = "zlib-rs"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f06ae92f42f5e5c42443fd094f245eb656abf56dd7cce9b8b263236565e00f2"
[[package]] [[package]]
name = "zopfli" name = "zopfli"
version = "0.8.2" version = "0.8.2"

@ -4,5 +4,5 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
calamine = "0.31.0" clap = { version = "4.5.48", features = ["derive"] }
umya-spreadsheet = "2.3.3" umya-spreadsheet = "2.3.3"

@ -0,0 +1,20 @@
use clap::Parser;
#[derive(Parser, Debug)]
pub struct Arguments {
/// path to the xlsx file
#[arg()]
pub file: String,
/// path to the output csv file
#[arg(short, long)]
pub output: Option<String>,
/// worksheets to convert to xlsx (numbers, or names, or nothing to convert all worksheets)
#[arg(short, long)]
pub worksheets: Vec<String>,
/// separator char. If many defined, use the first that is not used in cells.
#[arg(short, long, value_delimiter = ',', default_values_t = [';'])]
pub separator: Vec<char>,
/// char to replace separator char in cells. If no replacement, error will be fired
#[arg(short, long)]
pub replacement: Option<char>,
}

@ -1,25 +1,44 @@
use umya_spreadsheet::Worksheet; use umya_spreadsheet::{Spreadsheet, Worksheet};
#[derive(Debug)] #[derive(Debug)]
pub struct Extractor<'a> { pub struct Extractor<'a> {
sheet: &'a Worksheet, book: Spreadsheet,
sheet: Option<&'a Worksheet>,
pub separator: char, pub separator: char,
pub replacement: Option<char>,
pub merge_fill: MergeFill, pub merge_fill: MergeFill,
pub exclude_hidden: bool, pub exclude_hidden: bool,
} }
impl<'a> Extractor<'a> { impl<'a> Extractor<'a> {
pub fn new(sheet: &'a Worksheet) -> Self { pub fn new(book: Spreadsheet) -> Self {
Extractor { Extractor {
sheet, book,
sheet: None,
separator: ';', separator: ';',
replacement: None,
merge_fill: MergeFill::None, merge_fill: MergeFill::None,
exclude_hidden: true, exclude_hidden: true,
} }
} }
fn is_row_hidden(&self, row_index: u32) -> Option<bool> { pub fn new_with_options(
if let Some(row) = self.sheet.get_row_dimension(&row_index) { book: Spreadsheet,
separator: char,
replacement: Option<char>,
) -> Self {
Extractor {
book,
sheet: None,
separator,
replacement,
merge_fill: MergeFill::None,
exclude_hidden: true,
}
}
fn _is_row_hidden(&self, row_index: u32) -> Option<bool> {
if let Some(row) = self.sheet.unwrap().get_row_dimension(&row_index) {
if *row.get_hidden() { if *row.get_hidden() {
return Some(false); return Some(false);
} else { } else {
@ -29,8 +48,8 @@ impl<'a> Extractor<'a> {
None None
} }
fn is_column_hidden(&self, column_index: u32) -> Option<bool> { fn _is_column_hidden(&self, column_index: u32) -> Option<bool> {
if let Some(column) = self.sheet.get_column_dimension_by_number(&column_index) { if let Some(column) = self.sheet.unwrap().get_column_dimension_by_number(&column_index) {
if *column.get_hidden() { if *column.get_hidden() {
return Some(false); return Some(false);
} else { } else {
@ -40,8 +59,8 @@ impl<'a> Extractor<'a> {
None None
} }
fn is_cell_in_merge(&self, row_index: u32, column_index: u32) -> bool { fn _is_cell_in_merge(&self, row_index: u32, column_index: u32) -> bool {
let merges = self.sheet.get_merge_cells(); let merges = self.sheet.unwrap().get_merge_cells();
for merge in merges { for merge in merges {
if row_index >= *merge.get_coordinate_start_row().unwrap().get_num() if row_index >= *merge.get_coordinate_start_row().unwrap().get_num()
&& row_index <= *merge.get_coordinate_end_row().unwrap().get_num() && row_index <= *merge.get_coordinate_end_row().unwrap().get_num()

@ -1,14 +1,17 @@
use std::path::Path; use std::path::Path;
use clap::Parser;
use umya_spreadsheet::reader; use umya_spreadsheet::reader;
pub mod extractor; pub mod extractor;
use extractor::Extractor; use extractor::Extractor;
pub mod arguments;
use arguments::Arguments;
fn main() { fn main() {
let book = reader::xlsx::read(Path::new("anafi.xlsx")).unwrap(); let _args = Arguments::parse();
let sheets = book.get_sheet_collection();
let sheet = sheets.get(1).unwrap();
let extractor = Extractor::new(sheet);
let book = reader::xlsx::read(Path::new("anafi.xlsx")).unwrap();
let _extractor = Extractor::new(book);
} }

Loading…
Cancel
Save