Support table layout (#259)

* feat: Add layout type

* feat: Add layout

* 0.0.174
main
bokuweb 2021-03-23 12:01:09 +09:00 committed by GitHub
parent 147bebfa7f
commit 0b4d457b6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 235 additions and 38 deletions

2
.gitignore vendored
View File

@ -7,6 +7,8 @@ node_modules
*.docx# *.docx#
*.docx *.docx
output/*.docx output/*.docx
output/*.json
output/*.xml
vrt/screenshot/actual vrt/screenshot/actual
vrt/screenshot/diff vrt/screenshot/diff
vrt/report.html vrt/report.html

View File

@ -70,6 +70,7 @@ mod table_cell_property;
mod table_cell_width; mod table_cell_width;
mod table_grid; mod table_grid;
mod table_indent; mod table_indent;
mod table_layout;
mod table_property; mod table_property;
mod table_row; mod table_row;
mod table_row_property; mod table_row_property;
@ -160,6 +161,7 @@ pub use table_cell_property::*;
pub use table_cell_width::*; pub use table_cell_width::*;
pub use table_grid::*; pub use table_grid::*;
pub use table_indent::*; pub use table_indent::*;
pub use table_layout::*;
pub use table_property::*; pub use table_property::*;
pub use table_row::*; pub use table_row::*;
pub use table_row_property::*; pub use table_row_property::*;

View File

@ -64,6 +64,11 @@ impl Table {
self self
} }
pub fn layout(mut self, t: TableLayoutType) -> Table {
self.property = self.property.layout(t);
self
}
pub fn width(mut self, w: usize, t: WidthType) -> Table { pub fn width(mut self, w: usize, t: WidthType) -> Table {
self.property = self.property.width(w, t); self.property = self.property.width(w, t);
self self
@ -153,7 +158,7 @@ mod tests {
let t = Table::new(vec![]).set_grid(vec![100, 200, 300]); let t = Table::new(vec![]).set_grid(vec![100, 200, 300]);
assert_eq!( assert_eq!(
serde_json::to_string(&t).unwrap(), serde_json::to_string(&t).unwrap(),
r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"Auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":55,"left":54,"bottom":55,"right":55},"indent":null,"style":null}}"# r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"Auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":55,"left":54,"bottom":55,"right":55},"indent":null,"style":null,"layout":null}}"#
); );
} }
} }

View File

@ -0,0 +1,34 @@
use serde::{Serialize, Serializer};
use crate::documents::BuildXML;
use crate::types::*;
use crate::xml_builder::*;
#[derive(Debug, Clone, PartialEq)]
pub struct TableLayout {
layout_type: TableLayoutType,
}
impl TableLayout {
pub fn new(t: TableLayoutType) -> TableLayout {
TableLayout {
layout_type: t,
}
}
}
impl BuildXML for TableLayout {
fn build(&self) -> Vec<u8> {
let b = XMLBuilder::new();
b.table_layout(&self.layout_type.to_string()).build()
}
}
impl Serialize for TableLayout {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.layout_type.to_string())
}
}

View File

@ -14,6 +14,7 @@ pub struct TableProperty {
margins: TableCellMargins, margins: TableCellMargins,
indent: Option<TableIndent>, indent: Option<TableIndent>,
style: Option<TableStyle>, style: Option<TableStyle>,
layout: Option<TableLayout>,
} }
impl Default for TableProperty { impl Default for TableProperty {
@ -25,6 +26,7 @@ impl Default for TableProperty {
margins: TableCellMargins::new(), margins: TableCellMargins::new(),
indent: None, indent: None,
style: None, style: None,
layout: None,
} }
} }
} }
@ -85,6 +87,11 @@ impl TableProperty {
self.style = Some(TableStyle::new(s)); self.style = Some(TableStyle::new(s));
self self
} }
pub fn layout(mut self, t: TableLayoutType) -> Self {
self.layout = Some(TableLayout::new(t));
self
}
} }
impl BuildXML for TableProperty { impl BuildXML for TableProperty {
@ -97,6 +104,7 @@ impl BuildXML for TableProperty {
.add_child(&self.margins) .add_child(&self.margins)
.add_optional_child(&self.indent) .add_optional_child(&self.indent)
.add_optional_child(&self.style) .add_optional_child(&self.style)
.add_optional_child(&self.layout)
.close() .close()
.build() .build()
} }
@ -130,7 +138,7 @@ mod tests {
let p = TableProperty::new().indent(100); let p = TableProperty::new().indent(100);
assert_eq!( assert_eq!(
serde_json::to_string(&p).unwrap(), serde_json::to_string(&p).unwrap(),
r#"{"width":{"width":0,"widthType":"Auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":55,"left":54,"bottom":55,"right":55},"indent":{"width":100,"widthType":"DXA"},"style":null}"# r#"{"width":{"width":0,"widthType":"Auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":55,"left":54,"bottom":55,"right":55},"indent":{"width":100,"widthType":"DXA"},"style":null,"layout":null}"#
); );
} }
} }

View File

@ -15,6 +15,7 @@ pub mod spacing;
pub mod special_indent_type; pub mod special_indent_type;
pub mod style_type; pub mod style_type;
pub mod table_alignment_type; pub mod table_alignment_type;
pub mod table_layout_type;
pub mod text_direction_type; pub mod text_direction_type;
pub mod vertical_align_type; pub mod vertical_align_type;
pub mod vertical_merge_type; pub mod vertical_merge_type;
@ -37,6 +38,7 @@ pub use spacing::*;
pub use special_indent_type::*; pub use special_indent_type::*;
pub use style_type::*; pub use style_type::*;
pub use table_alignment_type::*; pub use table_alignment_type::*;
pub use table_layout_type::*;
pub use text_direction_type::*; pub use text_direction_type::*;
pub use vertical_align_type::*; pub use vertical_align_type::*;
pub use vertical_merge_type::*; pub use vertical_merge_type::*;

View File

@ -0,0 +1,33 @@
use serde::{Deserialize, Serialize};
use std::fmt;
use wasm_bindgen::prelude::*;
use super::errors;
use std::str::FromStr;
#[wasm_bindgen]
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum TableLayoutType {
Fixed,
Autofit,
}
impl fmt::Display for TableLayoutType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
TableLayoutType::Fixed => write!(f, "fixed"),
TableLayoutType::Autofit => write!(f, "autofit"),
}
}
}
impl FromStr for TableLayoutType {
type Err = errors::TypeError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"fixed" => Ok(TableLayoutType::Fixed),
_ => Ok(TableLayoutType::Autofit),
}
}
}

View File

@ -184,6 +184,7 @@ impl XMLBuilder {
open!(open_table_borders, "w:tblBorders"); open!(open_table_borders, "w:tblBorders");
open!(open_table_cell_margins, "w:tblCellMar"); open!(open_table_cell_margins, "w:tblCellMar");
closed!(table_layout, "w:tblLayout", "w:type");
closed_with_str!(table_style, "w:tblStyle"); closed_with_str!(table_style, "w:tblStyle");
closed_w_with_type_el!(table_width, "w:tblW"); closed_w_with_type_el!(table_width, "w:tblW");
closed_w_with_type_el!(table_indent, "w:tblInd"); closed_w_with_type_el!(table_indent, "w:tblInd");

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -442,6 +442,17 @@ export class Docx {
} }
} }
switch (t.property.layout) {
case "fixed": {
table = table.layout(wasm.TableLayoutType.Fixed);
break;
}
case "autofit": {
table = table.layout(wasm.TableLayoutType.Autofit);
break;
}
}
return table; return table;
} }

View File

@ -3,6 +3,7 @@ import { BorderJSON } from "./border";
import { HeightRule } from "../table-row"; import { HeightRule } from "../table-row";
import { TextDirectionType } from "../table-cell"; import { TextDirectionType } from "../table-cell";
import { ShadingJSON } from "./shading"; import { ShadingJSON } from "./shading";
import { TableLayoutType } from "../table";
export type TableCellChildJSON = ParagraphJSON; export type TableCellChildJSON = ParagraphJSON;
@ -67,6 +68,7 @@ export type TablePropertyJSON = {
widthType: WidthType; widthType: WidthType;
}; };
style: string | null; style: string | null;
layout: TableLayoutType | null;
}; };
export type TableJSON = { export type TableJSON = {

View File

@ -1,6 +1,7 @@
import { TableRow } from "./table-row"; import { TableRow } from "./table-row";
export type TableAlignmentType = "center" | "left" | "right"; export type TableAlignmentType = "center" | "left" | "right";
export type TableLayoutType = "fixed" | "autofit";
export type TableProperty = { export type TableProperty = {
indent?: number; indent?: number;
@ -12,6 +13,7 @@ export type TableProperty = {
bottom: number; bottom: number;
right: number; right: number;
}; };
layout?: TableLayoutType;
}; };
export class Table { export class Table {
@ -43,6 +45,11 @@ export class Table {
return this; return this;
} }
layout(l: TableLayoutType) {
this.property.layout = l;
return this;
}
width(w: number) { width(w: number) {
this.property.width = w; this.property.width = w;
return this; return this;

View File

@ -1,6 +1,6 @@
{ {
"name": "docx-wasm", "name": "docx-wasm",
"version": "0.0.173", "version": "0.0.174",
"main": "dist/node/index.js", "main": "dist/node/index.js",
"browser": "dist/web/index.js", "browser": "dist/web/index.js",
"author": "bokuweb <bokuweb12@gmail.com>", "author": "bokuweb <bokuweb12@gmail.com>",

View File

@ -43,7 +43,18 @@ impl Table {
self self
} }
pub fn set_cell_margins(mut self, top: usize, right: usize, bottom: usize, left: usize) -> Table { pub fn layout(mut self, t: docx_rs::TableLayoutType) -> Table {
self.0 = self.0.layout(t);
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); let m = docx_rs::TableCellMargins::new().margin(top, right, bottom, left);
self.0.property = self.0.property.set_margins(m); self.0.property = self.0.property.set_margins(m);
self self

View File

@ -797,6 +797,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -944,6 +945,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -3016,6 +3018,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -3118,6 +3121,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -3184,6 +3188,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -3286,6 +3291,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -5393,6 +5399,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -5495,6 +5502,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -5561,6 +5569,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -5663,6 +5672,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -5770,6 +5780,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -8460,6 +8471,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -8562,6 +8574,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -8628,6 +8641,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -8730,6 +8744,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -8832,6 +8847,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -8934,6 +8950,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -9036,6 +9053,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -9138,6 +9156,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -9240,6 +9259,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -9342,6 +9362,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -9444,6 +9465,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -9524,6 +9546,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -10346,6 +10369,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -10448,6 +10472,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -10538,6 +10563,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -10640,6 +10666,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -10736,6 +10763,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -10815,6 +10843,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -11363,6 +11392,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -11465,6 +11495,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -11531,6 +11562,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -11633,6 +11665,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -11735,6 +11768,7 @@ Object {
}, },
"indent": null, "indent": null,
"justification": "left", "justification": "left",
"layout": null,
"margins": Object { "margins": Object {
"bottom": 55, "bottom": 55,
"left": 54, "left": 54,
@ -11995,6 +12029,36 @@ exports[`writer should write page size 3`] = `
</w:num></w:numbering>" </w:num></w:numbering>"
`; `;
exports[`writer should write table layout 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
<Relationship Id=\\"rId1\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\\" Target=\\"styles.xml\\" />
<Relationship Id=\\"rId2\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable\\" Target=\\"fontTable.xml\\" />
<Relationship Id=\\"rId3\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\\" Target=\\"settings.xml\\" />
<Relationship Id=\\"rId4\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header\\" Target=\\"header1.xml\\" />
<Relationship Id=\\"rId5\\" Type=\\"http://schemas.microsoft.com/office/2011/relationships/commentsExtended\\" Target=\\"commentsExtended.xml\\" />
</Relationships>"
`;
exports[`writer should write table layout 2`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
<w:document xmlns:o=\\"urn:schemas-microsoft-com:office:office\\" xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:v=\\"urn:schemas-microsoft-com:vml\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\" xmlns:w10=\\"urn:schemas-microsoft-com:office:word\\" xmlns:wp=\\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\\" xmlns:wps=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\\" xmlns:wpg=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\\" xmlns:mc=\\"http://schemas.openxmlformats.org/markup-compatibility/2006\\" xmlns:wp14=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\\" xmlns:w14=\\"http://schemas.microsoft.com/office/word/2010/wordml\\" xmlns:w15=\\"http://schemas.microsoft.com/office/word/2012/wordml\\" mc:Ignorable=\\"w14 wp14\\">
<w:body><w:tbl><w:tblPr><w:tblW w:w=\\"0\\" w:type=\\"dxa\\" /><w:jc w:val=\\"left\\" /><w:tblBorders><w:top w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:left w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:bottom w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:right w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:insideH w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:insideV w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /></w:tblBorders><w:tblCellMar>
<w:top w:w=\\"55\\" w:type=\\"dxa\\" />
<w:left w:w=\\"54\\" w:type=\\"dxa\\" />
<w:bottom w:w=\\"55\\" w:type=\\"dxa\\" />
<w:right w:w=\\"55\\" w:type=\\"dxa\\" />
</w:tblCellMar><w:tblInd w:w=\\"0\\" w:type=\\"dxa\\" /><w:tblLayout w:type=\\"fixed\\" /></w:tblPr><w:tblGrid /><w:tr><w:trPr /><w:tc><w:tcPr><w:tcBorders><w:top w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:left w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:bottom w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:right w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:insideH w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:insideV w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /></w:tcBorders></w:tcPr><w:p w14:paraId=\\"00000001\\"><w:pPr><w:rPr /></w:pPr><w:r><w:rPr><w:rFonts /></w:rPr><w:t xml:space=\\"preserve\\">Hello!!</w:t></w:r></w:p></w:tc></w:tr></w:tbl><w:sectPr><w:pgSz w:w=\\"11906\\" w:h=\\"16838\\" /><w:pgMar w:top=\\"1985\\" w:right=\\"1701\\" w:bottom=\\"1701\\" w:left=\\"1701\\" w:header=\\"851\\" w:footer=\\"992\\" w:gutter=\\"0\\" /><w:headerReference w:type=\\"default\\" r:id=\\"rId4\\" /><w:cols w:space=\\"425\\" /><w:docGrid w:type=\\"lines\\" w:linePitch=\\"360\\" /></w:sectPr></w:body>
</w:document>"
`;
exports[`writer should write table layout 3`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
<w:numbering xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:o=\\"urn:schemas-microsoft-com:office:office\\" xmlns:v=\\"urn:schemas-microsoft-com:vml\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\"><w:abstractNum w:abstractNumId=\\"1\\"><w:lvl w:ilvl=\\"0\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%1.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"420\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"1\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%2)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"840\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"2\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%3\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"1260\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"3\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%4.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"1680\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"4\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%5)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2100\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"5\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%6\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2520\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"6\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"%7.\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"2940\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"7\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimal\\" /><w:lvlText w:val=\\"(%8)\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"3360\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl><w:lvl w:ilvl=\\"8\\"><w:start w:val=\\"1\\" /><w:numFmt w:val=\\"decimalEnclosedCircle\\" /><w:lvlText w:val=\\"%9\\" /><w:lvlJc w:val=\\"left\\" /><w:pPr><w:rPr /><w:ind w:left=\\"3780\\" w:right=\\"0\\" w:hanging=\\"420\\" /></w:pPr><w:rPr /></w:lvl></w:abstractNum><w:num w:numId=\\"1\\">
<w:abstractNumId w:val=\\"1\\" />
</w:num></w:numbering>"
`;
exports[`writer should write text border 1`] = ` exports[`writer should write text border 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?> "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\"> <Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">

View File

@ -216,6 +216,21 @@ describe("writer", () => {
} }
}); });
test("should write table layout", () => {
const p = new w.Paragraph().addRun(new w.Run().addText("Hello!!"));
const table = new w.Table()
.addRow(new w.TableRow().addCell(new w.TableCell().addParagraph(p)))
.layout("fixed");
const buffer = new w.Docx().addTable(table).build();
const z = new Zip(Buffer.from(buffer));
for (const e of z.getEntries()) {
if (e.entryName.match(/document.xml|numbering.xml/)) {
expect(z.readAsText(e)).toMatchSnapshot();
}
}
writeFileSync("../output/table_layout.docx", buffer);
});
test("should write text border", () => { test("should write text border", () => {
const p = new w.Paragraph() const p = new w.Paragraph()
.addRun(new w.Run().addText("Hello ")) .addRun(new w.Run().addText("Hello "))