From e83a4eeb9067870594bf452a76d37cc242f0be35 Mon Sep 17 00:00:00 2001 From: hayato-SMZ Date: Thu, 8 Sep 2022 13:37:38 +0900 Subject: [PATCH] Support table style (#531) * Fixed output of table_property when style is "Table" * add test for table_style --- docx-core/src/documents/elements/style.rs | 6 +++++- docx-core/src/documents/styles.rs | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docx-core/src/documents/elements/style.rs b/docx-core/src/documents/elements/style.rs index d7a2753..cac87b5 100644 --- a/docx-core/src/documents/elements/style.rs +++ b/docx-core/src/documents/elements/style.rs @@ -153,7 +153,11 @@ impl BuildXML for Style { .add_child(&self.name) .add_child(&self.run_property) .add_child(&self.paragraph_property); - + if self.style_type == StyleType::Table { + b = b + .add_child(&self.table_cell_property) + .add_child(&self.table_property); + } if let Some(ref based_on) = self.based_on { b = b.add_child(based_on) } diff --git a/docx-core/src/documents/styles.rs b/docx-core/src/documents/styles.rs index 4d64108..6b47ef7 100644 --- a/docx-core/src/documents/styles.rs +++ b/docx-core/src/documents/styles.rs @@ -103,6 +103,22 @@ mod tests { ); } + #[test] + fn test_table_style(){ + let c = + Styles::new().add_style(Style::new("Table", StyleType::Table).name("Table Style").table_property(TableProperty::new().set_margins(TableCellMargins::new().margin_left(108, WidthType::Dxa).margin_right(108,WidthType::Dxa)))); + let b = c.build(); + assert_eq!( + str::from_utf8(&b).unwrap(), + r#" + + + + +"# + ); + } + #[test] fn test_heading_style() { let c = Styles::new().add_style(Style::new("ToC", StyleType::Paragraph).name("heading 3"));