diff --git a/docx-core/src/documents/elements/table.rs b/docx-core/src/documents/elements/table.rs
index d03466b..c02dcd6 100644
--- a/docx-core/src/documents/elements/table.rs
+++ b/docx-core/src/documents/elements/table.rs
@@ -52,6 +52,11 @@ impl Table {
self
}
+ pub fn margins(mut self, margins: TableCellMargins) -> Self {
+ self.property = self.property.set_margins(margins);
+ self
+ }
+
pub fn set_borders(mut self, borders: TableBorders) -> Self {
self.property = self.property.set_borders(borders);
self
diff --git a/docx-core/src/documents/elements/table_cell_margins.rs b/docx-core/src/documents/elements/table_cell_margins.rs
index 1a4e407..d4d709a 100644
--- a/docx-core/src/documents/elements/table_cell_margins.rs
+++ b/docx-core/src/documents/elements/table_cell_margins.rs
@@ -29,7 +29,7 @@ impl TableCellMargins {
Default::default()
}
- pub fn margin(self, top: usize, left: usize, bottom: usize, right: usize) -> TableCellMargins {
+ pub fn margin(self, top: usize, right: usize, bottom: usize, left: usize) -> TableCellMargins {
TableCellMargins {
top,
left,
@@ -81,9 +81,9 @@ mod tests {
str::from_utf8(&b).unwrap(),
r#"
-
+
-
+
"#
);
}
diff --git a/docx-core/src/documents/elements/table_property.rs b/docx-core/src/documents/elements/table_property.rs
index 1fa724a..a692dda 100644
--- a/docx-core/src/documents/elements/table_property.rs
+++ b/docx-core/src/documents/elements/table_property.rs
@@ -47,6 +47,11 @@ impl TableProperty {
self
}
+ pub fn set_margins(mut self, margins: TableCellMargins) -> Self {
+ self.margins = margins;
+ self
+ }
+
pub fn set_borders(mut self, borders: TableBorders) -> Self {
self.borders = borders;
self
diff --git a/docx-wasm/js/index.ts b/docx-wasm/js/index.ts
index aeec539..dd482d5 100644
--- a/docx-wasm/js/index.ts
+++ b/docx-wasm/js/index.ts
@@ -329,9 +329,13 @@ export class Docx {
table = table.add_row(row);
});
table = table.set_grid(new Uint32Array(t.grid));
-
table = table.indent(t.property.indent || 0);
+ if (t.property.cellMargins) {
+ const { top, right, bottom, left } = t.property.cellMargins;
+ table = table.set_margins(top, right, bottom, left);
+ }
+
switch (t.property.align) {
case "center": {
table = table.align(wasm.TableAlignmentType.Center);
diff --git a/docx-wasm/js/table.ts b/docx-wasm/js/table.ts
index bd79fdf..c42b40a 100644
--- a/docx-wasm/js/table.ts
+++ b/docx-wasm/js/table.ts
@@ -6,6 +6,12 @@ export type TableProperty = {
indent?: number;
align?: TableAlignmentType;
width?: number;
+ cellMargins?: {
+ top: number;
+ left: number;
+ bottom: number;
+ right: number;
+ };
};
export class Table {
@@ -41,4 +47,9 @@ export class Table {
this.property.width = w;
return this;
}
+
+ cellMargins(top: number, right: number, bottom: number, left: number) {
+ this.property.cellMargins = { top, left, bottom, right };
+ return this;
+ }
}
diff --git a/docx-wasm/package.json b/docx-wasm/package.json
index e9480b9..d9ea0fb 100644
--- a/docx-wasm/package.json
+++ b/docx-wasm/package.json
@@ -1,6 +1,6 @@
{
"name": "docx-wasm",
- "version": "0.0.96",
+ "version": "0.0.98",
"main": "dist/node/index.js",
"browser": "dist/web/index.js",
"author": "bokuweb ",
diff --git a/docx-wasm/src/table.rs b/docx-wasm/src/table.rs
index fea4990..d1340e8 100644
--- a/docx-wasm/src/table.rs
+++ b/docx-wasm/src/table.rs
@@ -42,4 +42,10 @@ impl Table {
self.0 = self.0.width(w, docx_rs::WidthType::DXA);
self
}
+
+ pub fn set_cell_margins(mut self, top: usize, right: usize, bottom: usize, left: usize) -> Table {
+ let m = docx_rs::TableCellMargins::new().margin(top, right, bottom, left);
+ self.0.property = self.0.property.set_margins(m);
+ self
+ }
}