fix: Add rowHeight func (#177)

* fix: Add rowHeight func

* fix: rowHeight

* use: auto
main
bokuweb 2020-10-13 16:27:03 +09:00 committed by GitHub
parent 7f2750106d
commit cc980f6551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 26 additions and 6 deletions

6
Cargo.lock generated
View File

@ -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"

View File

@ -44,7 +44,11 @@ impl Default for TableRowProperty {
impl BuildXML for TableRowProperty {
fn build(&self) -> Vec<u8> {
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()
}
}

View File

@ -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");

View File

@ -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));

View File

@ -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;
}
}

View File

@ -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 <bokuweb12@gmail.com>",

View File

@ -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
}
}