parent
1941af9ef7
commit
046a7dd7e9
|
@ -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
|
||||
|
|
|
@ -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#"<w:tblCellMar>
|
||||
<w:top w:w="10" w:type="dxa" />
|
||||
<w:left w:w="20" w:type="dxa" />
|
||||
<w:left w:w="40" w:type="dxa" />
|
||||
<w:bottom w:w="30" w:type="dxa" />
|
||||
<w:right w:w="40" w:type="dxa" />
|
||||
<w:right w:w="20" w:type="dxa" />
|
||||
</w:tblCellMar>"#
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <bokuweb12@gmail.com>",
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue