Getting the background color when themed.
taylorh140 opened this issue · comments
I have been finding that argb colors are sometimes empty when getting the background color:
i have this method to get them so far (extracting to json)
if let Some(background_color) = cell.get_style().get_background_color() {
if background_color.get_indexed() != &0 {
tmp_cell_data["fill_color"] = json!(INDEXED_COLORS.get(*background_color.get_indexed() as usize));
} else if background_color.get_theme_index() != &0 {
// It would be more useful as argb
tmp_cell_data["theme_index"] = json!(*background_color.get_theme_index());
} else {
tmp_cell_data["fill_color"] = json!(background_color.get_argb().to_string());
}
}
I have to make a copy of the INDEXED_COLORS to extract them at the moment. And im not sure how to decode a themed color.
@taylorh140
Perhaps the following process can be used to obtain the color code.
let book = umya_spreadsheet::reader::xlsx::read(path).unwrap();
let color = book.get_theme().get_theme_elements()
.get_color_scheme()
.get_color_map()
.get(theme_index)
We will fix it so that arbg will always have a numerical value in the next version.
@MathNya This is super helpful. I'll see if I can get it to work on my end but that looks sort of like the direction I was heading.
And yeah argb always having a numerical value would be super nice and very helpful in my case.
Just fyi I have been working on a typst (its similar to a latex) importing plugin for xlsx sheets.
so far i can import values and merged cells and i should be able to handle the background colors now.
i think for the first release i would like to get (simple) text alignment and basic borders as well.
but your library is a key technology to make it possible.
Thanks!
I noticed when i used the solution above i get the darkest version of the themed color or the first row color instead of the subsequent ones :
so here i expect :
but end up with:
Note that my colors didn't quite turn out right here render wise but they do match the first row (see first image on this post)
@taylorh140
Thank you for your report.
Perhaps there is a bug somewhere.
We will investigate.