Open taylorh140 opened 8 months ago
@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!
@MathNya
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.
The latest version has been released. Please check it out.
Ok, so i did and its looking much better but it still has some issues.
Input: ThemeColors.xlsx
Output:
I have attached my input file.
Some look correct but others are off by a bit.
The associated code to grab this is:
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 {
tmp_cell_data["fill_color"] = json!(background_color.get_argb_with_theme(book.get_theme()));
} else {
tmp_cell_data["fill_color"] = json!(background_color.get_argb().to_string());
}
}
@taylorh140 Thank you for your report. We will investigate the cause.
@taylorh140 Sorry, we have considered correcting the problem, but it is difficult to respond. It will be some time before the response is complete.
I am patient. Thank you for your work. It looks like a difficult problem.
@taylorh140 Fixed issue. Please get the latest version and check it.
I happened to find a good document and was able to correct it. However, a special calculation is used to calculate the colors. Therefore, there are slight deviations between spreadsheets (Excel, LibreOffice, etc.).
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)
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.