diff --git a/Cargo.lock b/Cargo.lock index a67ece9..ec879cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -140,7 +140,7 @@ name = "docx-rs" version = "0.2.9" dependencies = [ "image 0.23.10 (registry+https://github.com/rust-lang/crates.io-index)", - "insta 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "insta 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.45 (registry+https://github.com/rust-lang/crates.io-index)", @@ -220,7 +220,7 @@ dependencies = [ [[package]] name = "insta" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "console 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -649,7 +649,7 @@ dependencies = [ "checksum gif 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "02efba560f227847cb41463a7395c514d127d4f74fff12ef0137fff1b84b96c4" "checksum hermit-abi 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eff2656d88f158ce120947499e971d743c05dbcbed62e5bd2f38f1698bbc3772" "checksum image 0.23.10 (registry+https://github.com/rust-lang/crates.io-index)" = "985fc06b1304d19c28d5c562ed78ef5316183f2b0053b46763a0b94862373c34" -"checksum insta 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d3463f26c58ee98b72e4eae1a6b4c28bc3320ab69d4836b55162362c2ec63fa6" +"checksum insta 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7e7528a20113cf7ca90eddfc2439c608188b6eafc0613964da2bd140c92acec" "checksum itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e" "checksum jpeg-decoder 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "5b47b4c4e017b01abdc5bcc126d2d1002e5a75bbe3ce73f9f4f311a916363704" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" diff --git a/docx-core/src/documents/elements/table_row_property.rs b/docx-core/src/documents/elements/table_row_property.rs index 85b692d..aee860d 100644 --- a/docx-core/src/documents/elements/table_row_property.rs +++ b/docx-core/src/documents/elements/table_row_property.rs @@ -44,7 +44,11 @@ impl Default for TableRowProperty { impl BuildXML for TableRowProperty { fn build(&self) -> Vec { - XMLBuilder::new().open_table_row_property().close().build() + let mut b = XMLBuilder::new().open_table_row_property(); + if let Some(h) = self.row_height { + b = b.table_row_height(&format!("{}", h), "auto") + } + b.close().build() } } diff --git a/docx-core/src/xml_builder/elements.rs b/docx-core/src/xml_builder/elements.rs index 7a65af6..6415c75 100644 --- a/docx-core/src/xml_builder/elements.rs +++ b/docx-core/src/xml_builder/elements.rs @@ -165,6 +165,8 @@ impl XMLBuilder { closed_w_with_type_el!(grid_column, "w:gridCol"); closed_w_with_type_el!(table_cell_width, "w:tcW"); + closed!(table_row_height, "w:trHeight", "w:val", "w:hRule"); + closed_with_usize!(grid_span, "w:gridSpan"); closed_with_str!(vertical_merge, "w:vMerge"); closed_with_str!(vertical_align, "w:vAlign"); diff --git a/docx-wasm/js/index.ts b/docx-wasm/js/index.ts index 0274311..f4c2e7e 100644 --- a/docx-wasm/js/index.ts +++ b/docx-wasm/js/index.ts @@ -338,6 +338,9 @@ export class Docx { const cell = this.buildCell(c); row = row.add_cell(cell); }); + if (r.height) { + row = row.row_height(r.height); + } table = table.add_row(row); }); table = table.set_grid(new Uint32Array(t.grid)); diff --git a/docx-wasm/js/table-row.ts b/docx-wasm/js/table-row.ts index de9e806..6b1abdd 100644 --- a/docx-wasm/js/table-row.ts +++ b/docx-wasm/js/table-row.ts @@ -3,12 +3,18 @@ import { TableCell } from "./table-cell"; export class TableRow { cells: TableCell[] = []; hasNumberings = false; + height: number | null = null; addCell(cell: TableCell) { if (cell.hasNumberings) { this.hasNumberings = true; } this.cells.push(cell); - this; + return this; + } + + rowHeight(h: number) { + this.height = h; + return this; } } diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 53d3ea6..4e172a4 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.109", + "version": "0.0.111", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/src/table_row.rs b/docx-wasm/src/table_row.rs index 6d4e3b5..d73772f 100644 --- a/docx-wasm/src/table_row.rs +++ b/docx-wasm/src/table_row.rs @@ -22,4 +22,9 @@ impl TableRow { self.0.cells.push(cell.take()); self } + + pub fn row_height(mut self, h: u32) -> TableRow { + self.0 = self.0.row_height(h as f32); + self + } }