calamine icon indicating copy to clipboard operation
calamine copied to clipboard

How to get "sheet" directly from buffer of bytes?

Open dbsxdbsx opened this issue 2 years ago • 2 comments

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();

dbsxdbsx avatar Jan 17 '22 10:01 dbsxdbsx

Also interested in this.

Struka9 avatar Apr 29 '22 13:04 Struka9

Update on this

Adamih avatar Aug 18 '22 20:08 Adamih

Closed with #256

tafia avatar Oct 20 '22 01:10 tafia

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!

sinistersnare avatar Dec 07 '22 21:12 sinistersnare