Open jamninetyfive opened 10 months ago
also hope support read buffer and filepath both them.
@jamninetyfive Thank you for contacting us. The image data is managed in a different location than the cell. You can get it with the following code. (I did not expect this kind of usage, so it is not a smart code.)
let img = book.get_sheet_by_name("Sheet1").unwrap().get_image("M17").unwrap();
match img.get_two_cell_anchor() {
Some(anchor) => match anchor.get_picture() {
Some(v) => {
dbg!(v.get_blip_fill().get_blip().get_image().get_image_name());
dbg!(v.get_blip_fill().get_blip().get_image().get_image_data());
}
None => {}
},
None => {}
}
match img.get_one_cell_anchor() {
Some(anchor) => match anchor.get_picture() {
Some(v) => {
dbg!(v.get_blip_fill().get_blip().get_image().get_image_name());
dbg!(v.get_blip_fill().get_blip().get_image().get_image_data());
}
None => {}
},
None => {}
}
Image objects in a sheet can also be retrieved in the following ways
let img_list = book.get_sheet_by_name("Sheet1").unwrap().get_image_collection();
Firstly, thank you for your great work in this library.
Using the first method, I still have a question that I am traversing the query col and row, and I don't know when to get images.
Secondly, in the second method, I can indeed obtain all the images, but I cannot obtain their original positions, such as their rows and columns.
Thank you again for responding to my question. Or do you have any suggestions for me.
This is my need.
@jamninetyfive You can now retrieve the position.
let img_list = book.get_sheet_by_name("Sheet1").unwrap().get_image_collection();
for img in img_list {
dbg!(img.get_coordinate());
}
Thank you for your patient reply. Can read buffer/blob be supported?
@jamninetyfive Is buffer/blob different from get_image_data()? If possible, a PR would be appreciated.
Thank you for your reply What I mean is to pass the Excel buffer for reading, not the path I will try PR, if I complete it, so far I am not good at rust, I am only good at JS
Fixed to make it easier to retrieve Image.
// get image data.
let img = book.get_sheet_by_name("Sheet1").unwrap().get_image("M17").unwrap();
// or
let img_list = book.get_sheet_by_name("Sheet1").unwrap().get_image_collection();
// get Coordinate.
assert_eq!(img.get_coordinate(), "M17");
assert_eq!(img.get_col(), &12);
assert_eq!(img.get_row(), &16);
// get file name.
assert_eq!(img.get_image_name(), "image1.png");
// get binary data.
dbg!(img.get_image_data());
// get base64 data.
dbg!(img.get_image_data_base64());
What if there are multiple images in a particular cell? What does get_image
return then?
Also, any way to get the width/height and/or the lower-right corner of the image? That's because an image may be larger than a single cell, so get_col
and get_row
only return the upper-left corner...
EDIT: Sorry, I now realize there are more API's that get multiple images and single-cell/two-cell ones. I'll experiment with them first. Sorry for the disruption.
when i read data i get empty string
or can I get cellType like stream, string, number....
What I want to get all data including image data and convert it to base64 and return it for use.