Closed KyGost closed 2 years ago
Oh.... Does Cell::set_style
even work?
Ah... PatternFill
's default is None
Ah, I'm silly and didn't read: https://docs.rs/umya-spreadsheet/latest/umya_spreadsheet/structs/struct.Style.html#
Hmm.... Using PatternValues::Solid
I can't make it anything but pure black.
I suspect that styles need some work and currently don't respond to background color.
Hmmm, there may be something wrong with the style settings. We will investigate.
Use set_foreground_color() instead of set_background_color(). This is also implemented in accordance with open xml, but it is confusing. We will take some countermeasures in the future.
This implementation worked well.
let mut color = umya_spreadsheet::Color::default();
color.set_argb(umya_spreadsheet::Color::COLOR_BLUE);
let mut pattern_fill = umya_spreadsheet::PatternFill::default();
pattern_fill.set_foreground_color(color);
let mut fill = umya_spreadsheet::Fill::default();
fill.set_pattern_fill(pattern_fill);
let mut style = umya_spreadsheet::Style::default();
style.set_fill(fill);
book.get_sheet_by_name_mut("Sheet2")
.unwrap()
.set_style("A2", style);
Here is an example of a smarter implementation.
// change background color.
book.get_sheet_by_name_mut("Sheet2")
.unwrap()
.get_style_mut("A1")
.get_fill_mut()
.get_pattern_fill_mut()
.get_foreground_color_mut()
.set_argb(umya_spreadsheet::Color::COLOR_BLUE);
Thanks, I'll try that. I had thought foreground color meant text color.
The following implementation has been added for changing the background color of cells. Please check after obtaining the latest version.
use umya_spreadsheet::*;
let mut book = new_file();
let mut style = book.get_sheet_by_name_mut("Sheet1").unwrap().get_style_mut("A1");
style.set_background_color(Color::COLOR_RED);
Looks nicer!
Is there a better way than this?: