|
|
|
|
@ -8,6 +8,7 @@ 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 => {
|
|
|
|
|
@ -23,6 +24,7 @@ pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 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),
|
|
|
|
|
@ -30,11 +32,18 @@ pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
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) {
|
|
|
|
|
Some(dim) => {
|
|
|
|
|
@ -45,6 +54,8 @@ pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
None => continue,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// for each column in row...
|
|
|
|
|
let mut first = true;
|
|
|
|
|
for j in 1..=num_cols {
|
|
|
|
|
if first {
|
|
|
|
|
@ -58,6 +69,7 @@ pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
None => continue,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// get value from cell depending on merged cells and fill merged policy
|
|
|
|
|
let cell_coordinate = cell.get_coordinate();
|
|
|
|
|
let mut value;
|
|
|
|
|
if let Some((col, row)) = merged_cells.in_merged_cell(
|
|
|
|
|
@ -71,6 +83,8 @@ pub fn xlsxtocsv(args: &Arguments) -> Result<(), Error> {
|
|
|
|
|
} else {
|
|
|
|
|
value = cell.get_formatted_value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// apply modifications to cells value (trim spaces, replace separator chars, line breaks etc.)
|
|
|
|
|
if args.trim_end {
|
|
|
|
|
value = String::from(value.trim_end());
|
|
|
|
|
}
|
|
|
|
|
|