From 1d1d83f520d9de860f1ea95eb273536a61b62f47 Mon Sep 17 00:00:00 2001 From: Ramon Buckland Date: Wed, 25 Jul 2018 07:00:32 +1000 Subject: [PATCH] version 0.2.0; --sheetname feature --- Cargo.toml | 4 ++-- RELEASE.md | 5 +++++ src/bin/md_tools.rs | 6 ++++-- src/excel.rs | 11 ++++++++--- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 RELEASE.md diff --git a/Cargo.toml b/Cargo.toml index 5d6dc88..b16a516 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "markdown_tools" -version = "0.1.2" +version = "0.2.0" authors = ["Ramon Buckland "] exclude = [ "doc/*", @@ -22,4 +22,4 @@ serde_yaml = "0.7" indexmap = "1.0.1" linked-hash-map = "0.5.1" docopt = "1.0.0" -calamine = "0.14" \ No newline at end of file +calamine = "0.14" diff --git a/RELEASE.md b/RELEASE.md new file mode 100644 index 0000000..aa0d041 --- /dev/null +++ b/RELEASE.md @@ -0,0 +1,5 @@ +* `0.1.2`- 24 Jul 2018 + - Fixed issue #1 where the `\r\n` return lines (pertinent inside MS XLS files in a Cell) would muck up the MD + as they were left with just a `\r` +* `0.2.0`- 25 Jul 2018 + - Added the `--sheetname ` to the command line tool. diff --git a/src/bin/md_tools.rs b/src/bin/md_tools.rs index 612c410..e4339c7 100644 --- a/src/bin/md_tools.rs +++ b/src/bin/md_tools.rs @@ -13,7 +13,7 @@ const USAGE: &str = " Markdown Tools Usage: - md-tools table -t + md-tools table -t [-s ] md-tools (-h | --help) md-tools --version @@ -22,6 +22,7 @@ Options: --version Show version. -t --type Input Type. Input Filename. + -s --sheetname When a Spreadsheet, restrict to just one of the sheets. "; #[derive(Debug, Deserialize)] @@ -29,6 +30,7 @@ struct Args { cmd_table: bool, flag_type: FileType, arg_filename: String, + flag_sheetname: Option } #[derive(Debug, Deserialize)] @@ -54,7 +56,7 @@ fn main() -> Result<(), String> { let result = match args.flag_type { FileType::YAML => read_yaml_file(args.arg_filename), - FileType::XLSX => spreadsheet_to_md(args.arg_filename), + FileType::XLSX => spreadsheet_to_md(args.arg_filename, args.flag_sheetname), _ => Err(String::from("not implemented")), }; diff --git a/src/excel.rs b/src/excel.rs index 3fedad9..44804c4 100644 --- a/src/excel.rs +++ b/src/excel.rs @@ -21,8 +21,8 @@ fn table_formatter( } } -pub fn spreadsheet_to_md(filename: String) -> Result { - let results = read_excel(filename); +pub fn spreadsheet_to_md(filename: String, sheet_name: Option) -> Result { + let results = read_excel(filename, sheet_name); if results.len() <= 1 { Ok(table_formatter(results[0].clone(), false)) } else { @@ -36,11 +36,16 @@ pub fn spreadsheet_to_md(filename: String) -> Result { pub fn read_excel( filename: String, + sheet_name: Option, ) -> Vec), (String, String)>> { // opens a new workbook let mut workbook = open_workbook_auto(filename).expect("Cannot open file"); - let sheet_names = workbook.sheet_names().to_owned(); + let sheet_names = if let Some(sheet_name) = sheet_name { + workbook.sheet_names().to_owned().into_iter().filter(|n| *n == sheet_name).to_owned().collect::>() + } else { + workbook.sheet_names().to_owned() + }; let sheets: Vec), (String, String)>> = sheet_names .iter()