calamine
calamine copied to clipboard
How to get "sheet" directly from buffer of bytes?
I am dealing some excel data sent from web. Some the type of data is bytes, not a file with a path. Is there a simple way to do so ?
Currently, I just know I can got it from an excel file from disk.
let file = r#"D:\PROJECT\testActixWeb\target\debug\ttt.xls"#;
let sheet = "Sheet1";
let sce = PathBuf::from(file);
match sce.extension().and_then(|s| s.to_str()) {
Some("xlsx") | Some("xlsm") | Some("xlsb") | Some("xls") => (),
_ => panic!("Expecting an excel file"),
}
let dest = sce.with_extension("csv");
let mut dest = BufWriter::new(File::create(dest).unwrap());
let mut xl = open_workbook_auto(&sce).unwrap();
Also interested in this.
Update on this
Closed with #256
The API has changed since #256 has merged. Now what I had to do was:
let buf = vec![....];
let cursor = Cursor::new(&buf[..]);
let mut workbook = open_workbook_auto_from_rs(cursor)?;
The key was to use a Cursor instead of the raw vec. Hope this helps people!