1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use calamine::{open_workbook, Reader, Xlsx};
pub struct Excel {
path: String,
}
impl Excel {
pub fn new(path: &str) -> Excel {
Excel {
path: path.to_string()
}
}
pub fn to_csv(self, sheet: &str, output_file: &str) {
let mut excel: Xlsx<_> = open_workbook(self.path).unwrap();
let mut outputs = Vec::new();
if let Some(Ok(r)) = excel.worksheet_range(sheet) {
for row in r.rows() {
let mut output_row = vec![];
for value in row {
output_row.push(value.to_string());
}
outputs.push(output_row);
}
}
let mut writer = csv::Writer::from_path(output_file).unwrap();
for row in outputs {
writer.write_record(row.clone()).unwrap();
}
}
}