Hi, newbie here.
I read the xlsx files on the client side and send their xml content to the server, so I need a way to read the files from the xml, how do I achieve that? I see open_workbook requires the path of the file though.
Sorry if that's a basic question, but I wasn't able to find an answer.
Edit:
#[derive(Deserialize, Debug)]
pub struct Payload {
pub data: Vec<String>,
}
async fn hello(Json(body): Json<Payload>) -> impl IntoResponse {
println!("{:?}", &body.data[0]);
let bytes = &body.data[0].as_bytes();
let reader = Cursor::new(&bytes);
let xlsx = open_workbook_auto_from_rs(reader).unwrap();
let sheets = xlsx.sheet_names().to_owned();
println!("{:?}", sheets);
Json(message)
}
I found open_workbook_auto_from_rs, I believe that's what I want, not sure if I'm doing this correctly, but I keep getting this:
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Msg("Cannot detect file format")'
Nevermind, I fixed it. I returned a formdata from my client, and the sent the file(s) binaries as the fields, then read the bytes from open_workbook_from_rs. Worked good.
Hi, newbie here. I read the xlsx files on the client side and send their xml content to the server, so I need a way to read the files from the xml, how do I achieve that? I see open_workbook requires the path of the file though. Sorry if that's a basic question, but I wasn't able to find an answer.
Edit:
I found
open_workbook_auto_from_rs
, I believe that's what I want, not sure if I'm doing this correctly, but I keep getting this:This is what the data I'm sending from the client kinda looks like. (incomplete)
Edit 2:
This errors with
Msg("Sheets must be created from a Path")
. I don't know why, I looked into https://github.com/tafia/calamine/blob/c66195c76676b29bdd78c6e977b3333082dc6fd5/src/auto.rs#L83C1-L85C6, no idea why it blindly returns an err.I tried the
open_workbook_from_rs
function, but that as well errors.Zip(Io(Error { kind: UnexpectedEof, message: "failed to fill whole buffer" }))