Skip to content

Commit 967ab61

Browse files
author
DESKTOP-U434MT0\hiro
committed
Minor Correction
1 parent 15fd762 commit 967ab61

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "umya-spreadsheet"
3-
version = "0.6.0"
3+
version = "0.7.0"
44
authors = ["MathNya <umya.net.info@gmail.com>"]
55
repository = "https://github.com/MathNya/umya-spreadsheet"
66
keywords = ["excel", "spreadsheet", "xlsx", "reader", "writer"]

src/structs/cell.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,11 @@ impl Cell {
391391
shared_string_table: Arc<RwLock<SharedStringTable>>,
392392
stylesheet: &mut Stylesheet,
393393
) {
394-
let empty_flag = self.cell_value.is_empty();
394+
let empty_flag_value = self.cell_value.is_empty();
395+
let empty_flag_style = self.style.is_empty();
396+
if empty_flag_value && empty_flag_style {
397+
return;
398+
}
395399

396400
// c
397401
let mut attributes: Vec<(&str, &str)> = Vec::new();
@@ -407,8 +411,8 @@ impl Cell {
407411
attributes.push(("s", &xf_index_str));
408412
}
409413

410-
if !empty_flag {
411-
write_start_tag(writer, "c", attributes, empty_flag);
414+
if !empty_flag_value {
415+
write_start_tag(writer, "c", attributes, false);
412416
// f
413417
match &self.cell_value.formula {
414418
Some(v) => {
@@ -439,6 +443,8 @@ impl Cell {
439443
write_end_tag(writer, "v");
440444

441445
write_end_tag(writer, "c");
446+
} else {
447+
write_start_tag(writer, "c", attributes, true);
442448
}
443449
}
444450
}

src/structs/style.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,25 @@ impl Style {
194194
self
195195
}
196196

197+
pub(crate) fn is_empty(&self) -> bool {
198+
if self.font.is_some() {
199+
return false;
200+
}
201+
if self.fill.is_some() {
202+
return false;
203+
}
204+
if self.borders.is_some() {
205+
return false;
206+
}
207+
if self.alignment.is_some() {
208+
return false;
209+
}
210+
if self.numbering_format.is_some() {
211+
return false;
212+
}
213+
true
214+
}
215+
197216
pub(crate) fn get_defalut_value() -> Self {
198217
let mut def = Self::default();
199218
def.set_font(Font::get_defalut_value());

src/structs/worksheet.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,11 @@ impl Worksheet {
430430
self.cell_collection.get_mut(col, row).get_style_mut()
431431
}
432432

433+
pub fn set_style(&mut self, coordinate: &str, style: Style) -> &mut Self {
434+
let (col, row) = index_from_coordinate_simple(coordinate);
435+
self.set_style_by_column_and_row(&col, &row, style)
436+
}
437+
433438
/// Set the style by specifying the column number and row number.
434439
/// # Arguments
435440
/// * `col` - Specify the column number. (first column number is 1)

tests/integration_test.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,28 @@ fn new_file_and_edit() {
750750
.get_color_mut()
751751
.set_argb("00FF0000");
752752

753+
// change background color.
754+
book.get_sheet_by_name_mut("Sheet2")
755+
.unwrap()
756+
.get_style_mut("A1")
757+
.get_fill_mut()
758+
.get_pattern_fill_mut()
759+
.get_foreground_color_mut()
760+
.set_argb(umya_spreadsheet::Color::COLOR_BLUE);
761+
762+
// change background color part2.
763+
let mut color = umya_spreadsheet::Color::default();
764+
color.set_argb(umya_spreadsheet::Color::COLOR_BLUE);
765+
let mut pattern_fill = umya_spreadsheet::PatternFill::default();
766+
pattern_fill.set_foreground_color(color);
767+
let mut fill = umya_spreadsheet::Fill::default();
768+
fill.set_pattern_fill(pattern_fill);
769+
let mut style = umya_spreadsheet::Style::default();
770+
style.set_fill(fill);
771+
book.get_sheet_by_name_mut("Sheet2")
772+
.unwrap()
773+
.set_style("A2", style);
774+
753775
let worksheet = book.get_sheet_by_name_mut("Sheet3").unwrap();
754776
worksheet.get_column_dimension_mut("A").set_auto_width(true);
755777

0 commit comments

Comments
 (0)