|
|
|
|
@ -4,7 +4,7 @@ use umya_spreadsheet::{Range, Worksheet, reader};
|
|
|
|
|
use crate::arguments::{Arguments, TrimSpaces};
|
|
|
|
|
use crate::error::Error;
|
|
|
|
|
|
|
|
|
|
pub fn xlsxtocsv2(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
let book = reader::xlsx::read(Path::new(&args.file))
|
|
|
|
|
.expect(format!("Can't open {}", args.file).as_str());
|
|
|
|
|
|
|
|
|
|
@ -35,66 +35,37 @@ pub fn xlsxtocsv2(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
// get all the merged cells
|
|
|
|
|
let merged_cells = MergedCells::new(sheet, horiz, vert);
|
|
|
|
|
|
|
|
|
|
// get size of the worksheet
|
|
|
|
|
let mut col_max = 0;
|
|
|
|
|
let mut row_max = 0;
|
|
|
|
|
// get non-empty value size of the worksheet
|
|
|
|
|
let mut num_cols = 0;
|
|
|
|
|
let mut num_rows = 0;
|
|
|
|
|
|
|
|
|
|
for cell in sheet.get_cell_collection() {
|
|
|
|
|
let value = cell.get_formatted_value();
|
|
|
|
|
|
|
|
|
|
if value == "" {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for cell in sheet.get_cell_collection_sorted() {
|
|
|
|
|
let coord = cell.get_coordinate();
|
|
|
|
|
let col_num = coord.get_col_num().clone();
|
|
|
|
|
let row_num = coord.get_row_num().clone();
|
|
|
|
|
if col_num > col_max {
|
|
|
|
|
col_max = col_num;
|
|
|
|
|
if col_num > num_cols {
|
|
|
|
|
num_cols = col_num;
|
|
|
|
|
}
|
|
|
|
|
if row_num > row_max {
|
|
|
|
|
col_max = col_num;
|
|
|
|
|
if row_num > num_rows {
|
|
|
|
|
num_rows = row_num;
|
|
|
|
|
}
|
|
|
|
|
println!("({}, {})", col_num, row_num);
|
|
|
|
|
}
|
|
|
|
|
println!("highest : ({}, {})", col_max, row_max);
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
let mut empty_row = String::from("");
|
|
|
|
|
for _ in 1..num_cols {
|
|
|
|
|
empty_row += ";"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
let book = reader::xlsx::read(Path::new(&args.file))
|
|
|
|
|
.expect(format!("Can't open {}", args.file).as_str());
|
|
|
|
|
|
|
|
|
|
// get the sheet from name or number if specified, else the first of the spreadsheet
|
|
|
|
|
let sheet = match book.get_sheet_by_name(&args.worksheet) {
|
|
|
|
|
Some(sheet) => sheet,
|
|
|
|
|
None => {
|
|
|
|
|
let sheetnum: u32 = match args.worksheet.parse() {
|
|
|
|
|
Ok(sheetnum) => sheetnum,
|
|
|
|
|
Err(_) => return Err(Error::new("cannot open sheet")),
|
|
|
|
|
};
|
|
|
|
|
let sheet = match book.get_sheet(&(sheetnum as usize)) {
|
|
|
|
|
Some(sheet) => sheet,
|
|
|
|
|
None => return Err(Error::new("cannot open sheet")),
|
|
|
|
|
};
|
|
|
|
|
sheet
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// set the merged cells policy
|
|
|
|
|
let (horiz, vert) = match args.fill_merged_cells {
|
|
|
|
|
crate::arguments::FillMergedCells::None => (false, false),
|
|
|
|
|
crate::arguments::FillMergedCells::Horizontal => (true, false),
|
|
|
|
|
crate::arguments::FillMergedCells::Vertical => (false, true),
|
|
|
|
|
crate::arguments::FillMergedCells::Both => (true, true),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// get all the merged cells
|
|
|
|
|
let merged_cells = MergedCells::new(sheet, horiz, vert);
|
|
|
|
|
|
|
|
|
|
// get size of the worksheet
|
|
|
|
|
let (num_cols, num_rows) = sheet.get_highest_column_and_row();
|
|
|
|
|
|
|
|
|
|
// TODO get every hidden columns
|
|
|
|
|
|
|
|
|
|
// for each row...
|
|
|
|
|
for i in 1..=num_rows {
|
|
|
|
|
|
|
|
|
|
// Avoid hidden rows if asked for
|
|
|
|
|
if !args.include_hidden_lines {
|
|
|
|
|
match sheet.get_row_dimension(&i) {
|
|
|
|
|
@ -103,7 +74,10 @@ pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None => continue,
|
|
|
|
|
None => {
|
|
|
|
|
println!("{}", empty_row);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -118,7 +92,7 @@ pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
|
|
|
|
|
let cell = match sheet.get_cell((j, i)) {
|
|
|
|
|
Some(cell) => cell,
|
|
|
|
|
None => continue,
|
|
|
|
|
None => break,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// get value from cell depending on merged cells and fill merged policy
|
|
|
|
|
@ -209,4 +183,3 @@ impl MergedCells {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|