Improve cell borders (#243)

* feat: Support tl2br / tr2bl

* fix: some bugs

* fix: example

* update: snaps

* update
main
bokuweb 2021-03-16 16:09:39 +09:00 committed by GitHub
parent a2ca156f83
commit 8890385f67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 394 additions and 175 deletions

View File

@ -9,9 +9,9 @@ pub fn main() -> Result<(), DocxError> {
TableCell::new()
.add_paragraph(Paragraph::new())
.grid_span(2)
.clear_border(BorderPosition::Left)
.clear_border(BorderPosition::Bottom)
.clear_border(BorderPosition::Right),
.clear_border(TableCellBorderPosition::Left)
.clear_border(TableCellBorderPosition::Bottom)
.clear_border(TableCellBorderPosition::Right),
TableCell::new()
.add_paragraph(Paragraph::new().add_run(Run::new().add_text("Hello")))
.vertical_align(VAlignType::Center)

View File

@ -84,7 +84,7 @@ impl Table {
self
}
pub fn clear_border(mut self, position: BorderPosition) -> Self {
pub fn clear_border(mut self, position: TableBorderPosition) -> Self {
self.property = self.property.clear_border(position);
self
}

View File

@ -22,12 +22,12 @@ pub struct TableBorder {
pub border_type: BorderType,
pub size: usize,
pub color: String,
position: BorderPosition,
position: TableBorderPosition,
space: usize,
}
impl TableBorder {
pub fn new(position: BorderPosition) -> TableBorder {
pub fn new(position: TableBorderPosition) -> TableBorder {
TableBorder {
position,
border_type: BorderType::Single,
@ -57,22 +57,22 @@ impl BuildXML for TableBorder {
fn build(&self) -> Vec<u8> {
let base = XMLBuilder::new();
let base = match self.position {
BorderPosition::Top => {
TableBorderPosition::Top => {
base.border_top(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::Left => {
TableBorderPosition::Left => {
base.border_left(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::Bottom => {
TableBorderPosition::Bottom => {
base.border_bottom(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::Right => {
TableBorderPosition::Right => {
base.border_right(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::InsideH => {
TableBorderPosition::InsideH => {
base.border_inside_h(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::InsideV => {
TableBorderPosition::InsideV => {
base.border_inside_v(self.border_type, self.size, self.space, &self.color)
}
};
@ -94,12 +94,12 @@ pub struct TableBorders {
impl Default for TableBorders {
fn default() -> TableBorders {
TableBorders {
top: Some(TableBorder::new(BorderPosition::Top)),
left: Some(TableBorder::new(BorderPosition::Left)),
bottom: Some(TableBorder::new(BorderPosition::Bottom)),
right: Some(TableBorder::new(BorderPosition::Right)),
inside_h: Some(TableBorder::new(BorderPosition::InsideH)),
inside_v: Some(TableBorder::new(BorderPosition::InsideV)),
top: Some(TableBorder::new(TableBorderPosition::Top)),
left: Some(TableBorder::new(TableBorderPosition::Left)),
bottom: Some(TableBorder::new(TableBorderPosition::Bottom)),
right: Some(TableBorder::new(TableBorderPosition::Right)),
inside_h: Some(TableBorder::new(TableBorderPosition::InsideH)),
inside_v: Some(TableBorder::new(TableBorderPosition::InsideV)),
}
}
}
@ -122,38 +122,40 @@ impl TableBorders {
pub fn set(mut self, border: TableBorder) -> Self {
match border.position {
BorderPosition::Top => self.top = Some(border),
BorderPosition::Left => self.left = Some(border),
BorderPosition::Bottom => self.bottom = Some(border),
BorderPosition::Right => self.right = Some(border),
BorderPosition::InsideH => self.inside_h = Some(border),
BorderPosition::InsideV => self.inside_v = Some(border),
TableBorderPosition::Top => self.top = Some(border),
TableBorderPosition::Left => self.left = Some(border),
TableBorderPosition::Bottom => self.bottom = Some(border),
TableBorderPosition::Right => self.right = Some(border),
TableBorderPosition::InsideH => self.inside_h = Some(border),
TableBorderPosition::InsideV => self.inside_v = Some(border),
};
self
}
pub fn clear(mut self, position: BorderPosition) -> Self {
pub fn clear(mut self, position: TableBorderPosition) -> Self {
let nil = TableBorder::new(position.clone()).border_type(BorderType::Nil);
match position {
BorderPosition::Top => self.top = Some(nil),
BorderPosition::Left => self.left = Some(nil),
BorderPosition::Bottom => self.bottom = Some(nil),
BorderPosition::Right => self.right = Some(nil),
BorderPosition::InsideH => self.inside_h = Some(nil),
BorderPosition::InsideV => self.inside_v = Some(nil),
TableBorderPosition::Top => self.top = Some(nil),
TableBorderPosition::Left => self.left = Some(nil),
TableBorderPosition::Bottom => self.bottom = Some(nil),
TableBorderPosition::Right => self.right = Some(nil),
TableBorderPosition::InsideH => self.inside_h = Some(nil),
TableBorderPosition::InsideV => self.inside_v = Some(nil),
};
self
}
pub fn clear_all(mut self) -> Self {
self.top = Some(TableBorder::new(BorderPosition::Top).border_type(BorderType::Nil));
self.left = Some(TableBorder::new(BorderPosition::Left).border_type(BorderType::Nil));
self.bottom = Some(TableBorder::new(BorderPosition::Bottom).border_type(BorderType::Nil));
self.right = Some(TableBorder::new(BorderPosition::Right).border_type(BorderType::Nil));
self.top = Some(TableBorder::new(TableBorderPosition::Top).border_type(BorderType::Nil));
self.left = Some(TableBorder::new(TableBorderPosition::Left).border_type(BorderType::Nil));
self.bottom =
Some(TableBorder::new(TableBorderPosition::Bottom).border_type(BorderType::Nil));
self.right =
Some(TableBorder::new(TableBorderPosition::Right).border_type(BorderType::Nil));
self.inside_h =
Some(TableBorder::new(BorderPosition::InsideH).border_type(BorderType::Nil));
Some(TableBorder::new(TableBorderPosition::InsideH).border_type(BorderType::Nil));
self.inside_v =
Some(TableBorder::new(BorderPosition::InsideV).border_type(BorderType::Nil));
Some(TableBorder::new(TableBorderPosition::InsideV).border_type(BorderType::Nil));
self
}
}
@ -193,8 +195,8 @@ mod tests {
#[test]
fn test_table_borders_set() {
let b = TableBorders::new()
.set(TableBorder::new(BorderPosition::Left).color("AAAAAA"))
.clear(BorderPosition::Top)
.set(TableBorder::new(TableBorderPosition::Left).color("AAAAAA"))
.clear(TableBorderPosition::Top)
.build();
assert_eq!(
str::from_utf8(&b).unwrap(),

View File

@ -98,7 +98,7 @@ impl TableCell {
self
}
pub fn clear_border(mut self, position: BorderPosition) -> Self {
pub fn clear_border(mut self, position: TableCellBorderPosition) -> Self {
self.property = self.property.clear_border(position);
self
}
@ -137,6 +137,10 @@ impl BuildXML for TableCell {
}
}
}
// INFO: We need to add empty paragraph when parent cell includes only cell.
if self.children.is_empty() {
b = b.add_child(&Paragraph::new())
}
b.close().build()
}
}
@ -152,7 +156,7 @@ mod tests {
#[test]
fn test_cell() {
let b = TableCell::new().build();
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:tc><w:tcPr /></w:tc>"#);
assert_eq!(str::from_utf8(&b).unwrap(), r#"<w:tc><w:tcPr /><w:p w14:paraId="12345678"><w:pPr><w:rPr /></w:pPr></w:p></w:tc>"#);
}
#[test]

View File

@ -22,12 +22,12 @@ pub struct TableCellBorder {
pub border_type: BorderType,
pub size: usize,
pub color: String,
position: BorderPosition,
position: TableCellBorderPosition,
space: usize,
}
impl TableCellBorder {
pub fn new(position: BorderPosition) -> TableCellBorder {
pub fn new(position: TableCellBorderPosition) -> TableCellBorder {
TableCellBorder {
position,
border_type: BorderType::Single,
@ -69,24 +69,30 @@ impl BuildXML for TableCellBorder {
fn build(&self) -> Vec<u8> {
let base = XMLBuilder::new();
let base = match self.position {
BorderPosition::Top => {
TableCellBorderPosition::Top => {
base.border_top(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::Left => {
TableCellBorderPosition::Left => {
base.border_left(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::Bottom => {
TableCellBorderPosition::Bottom => {
base.border_bottom(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::Right => {
TableCellBorderPosition::Right => {
base.border_right(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::InsideH => {
TableCellBorderPosition::InsideH => {
base.border_inside_h(self.border_type, self.size, self.space, &self.color)
}
BorderPosition::InsideV => {
TableCellBorderPosition::InsideV => {
base.border_inside_v(self.border_type, self.size, self.space, &self.color)
}
TableCellBorderPosition::Tr2bl => {
base.border_tr2bl(self.border_type, self.size, self.space, &self.color)
}
TableCellBorderPosition::Tl2br => {
base.border_tl2br(self.border_type, self.size, self.space, &self.color)
}
};
base.build()
}
@ -101,17 +107,21 @@ pub struct TableCellBorders {
right: Option<TableCellBorder>,
inside_h: Option<TableCellBorder>,
inside_v: Option<TableCellBorder>,
tr2bl: Option<TableCellBorder>,
tl2br: Option<TableCellBorder>,
}
impl Default for TableCellBorders {
fn default() -> TableCellBorders {
TableCellBorders {
top: Some(TableCellBorder::new(BorderPosition::Top)),
left: Some(TableCellBorder::new(BorderPosition::Left)),
bottom: Some(TableCellBorder::new(BorderPosition::Bottom)),
right: Some(TableCellBorder::new(BorderPosition::Right)),
inside_h: Some(TableCellBorder::new(BorderPosition::InsideH)),
inside_v: Some(TableCellBorder::new(BorderPosition::InsideV)),
top: Some(TableCellBorder::new(TableCellBorderPosition::Top)),
left: Some(TableCellBorder::new(TableCellBorderPosition::Left)),
bottom: Some(TableCellBorder::new(TableCellBorderPosition::Bottom)),
right: Some(TableCellBorder::new(TableCellBorderPosition::Right)),
inside_h: Some(TableCellBorder::new(TableCellBorderPosition::InsideH)),
inside_v: Some(TableCellBorder::new(TableCellBorderPosition::InsideV)),
tr2bl: None,
tl2br: None,
}
}
}
@ -129,44 +139,60 @@ impl TableCellBorders {
right: None,
inside_h: None,
inside_v: None,
tr2bl: None,
tl2br: None,
}
}
pub fn set(mut self, border: TableCellBorder) -> Self {
match border.position {
BorderPosition::Top => self.top = Some(border),
BorderPosition::Left => self.left = Some(border),
BorderPosition::Bottom => self.bottom = Some(border),
BorderPosition::Right => self.right = Some(border),
BorderPosition::InsideH => self.inside_h = Some(border),
BorderPosition::InsideV => self.inside_v = Some(border),
TableCellBorderPosition::Top => self.top = Some(border),
TableCellBorderPosition::Left => self.left = Some(border),
TableCellBorderPosition::Bottom => self.bottom = Some(border),
TableCellBorderPosition::Right => self.right = Some(border),
TableCellBorderPosition::InsideH => self.inside_h = Some(border),
TableCellBorderPosition::InsideV => self.inside_v = Some(border),
TableCellBorderPosition::Tr2bl => self.tr2bl = Some(border),
TableCellBorderPosition::Tl2br => self.tl2br = Some(border),
};
self
}
pub fn clear(mut self, position: BorderPosition) -> Self {
pub fn clear(mut self, position: TableCellBorderPosition) -> Self {
let nil = TableCellBorder::new(position.clone()).border_type(BorderType::Nil);
match position {
BorderPosition::Top => self.top = Some(nil),
BorderPosition::Left => self.left = Some(nil),
BorderPosition::Bottom => self.bottom = Some(nil),
BorderPosition::Right => self.right = Some(nil),
BorderPosition::InsideH => self.inside_h = Some(nil),
BorderPosition::InsideV => self.inside_v = Some(nil),
TableCellBorderPosition::Top => self.top = Some(nil),
TableCellBorderPosition::Left => self.left = Some(nil),
TableCellBorderPosition::Bottom => self.bottom = Some(nil),
TableCellBorderPosition::Right => self.right = Some(nil),
TableCellBorderPosition::InsideH => self.inside_h = Some(nil),
TableCellBorderPosition::InsideV => self.inside_v = Some(nil),
TableCellBorderPosition::Tr2bl => self.tr2bl = Some(nil),
TableCellBorderPosition::Tl2br => self.tl2br = Some(nil),
};
self
}
pub fn clear_all(mut self) -> Self {
self.top = Some(TableCellBorder::new(BorderPosition::Top).border_type(BorderType::Nil));
self.left = Some(TableCellBorder::new(BorderPosition::Left).border_type(BorderType::Nil));
self.bottom =
Some(TableCellBorder::new(BorderPosition::Bottom).border_type(BorderType::Nil));
self.right = Some(TableCellBorder::new(BorderPosition::Right).border_type(BorderType::Nil));
self.inside_h =
Some(TableCellBorder::new(BorderPosition::InsideH).border_type(BorderType::Nil));
self.inside_v =
Some(TableCellBorder::new(BorderPosition::InsideV).border_type(BorderType::Nil));
self.top =
Some(TableCellBorder::new(TableCellBorderPosition::Top).border_type(BorderType::Nil));
self.left =
Some(TableCellBorder::new(TableCellBorderPosition::Left).border_type(BorderType::Nil));
self.bottom = Some(
TableCellBorder::new(TableCellBorderPosition::Bottom).border_type(BorderType::Nil),
);
self.right =
Some(TableCellBorder::new(TableCellBorderPosition::Right).border_type(BorderType::Nil));
self.inside_h = Some(
TableCellBorder::new(TableCellBorderPosition::InsideH).border_type(BorderType::Nil),
);
self.inside_v = Some(
TableCellBorder::new(TableCellBorderPosition::InsideV).border_type(BorderType::Nil),
);
self.tl2br =
Some(TableCellBorder::new(TableCellBorderPosition::Tl2br).border_type(BorderType::Nil));
self.tr2bl =
Some(TableCellBorder::new(TableCellBorderPosition::Tr2bl).border_type(BorderType::Nil));
self
}
}
@ -181,6 +207,8 @@ impl BuildXML for TableCellBorders {
.add_optional_child(&self.right)
.add_optional_child(&self.inside_h)
.add_optional_child(&self.inside_v)
.add_optional_child(&self.tl2br)
.add_optional_child(&self.tr2bl)
.close()
.build()
}

View File

@ -56,7 +56,7 @@ impl TableCellProperty {
self
}
pub fn clear_border(mut self, position: BorderPosition) -> Self {
pub fn clear_border(mut self, position: TableCellBorderPosition) -> Self {
self.borders = Some(self.borders.unwrap_or_default().clear(position));
self
}

View File

@ -71,7 +71,7 @@ impl TableProperty {
self
}
pub fn clear_border(mut self, position: BorderPosition) -> Self {
pub fn clear_border(mut self, position: TableBorderPosition) -> Self {
self.borders = self.borders.clear(position);
self
}

View File

@ -67,7 +67,7 @@ mod tests {
let b = TableRow::new(vec![TableCell::new()]).build();
assert_eq!(
str::from_utf8(&b).unwrap(),
r#"<w:tr><w:trPr /><w:tc><w:tcPr /></w:tc></w:tr>"#
r#"<w:tr><w:trPr /><w:tc><w:tcPr /><w:p w14:paraId="12345678"><w:pPr><w:rPr /></w:pPr></w:p></w:tc></w:tr>"#
);
}

View File

@ -20,7 +20,7 @@ impl ElementReader for TableBorders {
match e {
XMLElement::Top => {
let attr = read_border(&attributes)?;
let mut border = TableBorder::new(BorderPosition::Top)
let mut border = TableBorder::new(TableBorderPosition::Top)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -31,7 +31,7 @@ impl ElementReader for TableBorders {
}
XMLElement::Right => {
let attr = read_border(&attributes)?;
let mut border = TableBorder::new(BorderPosition::Right)
let mut border = TableBorder::new(TableBorderPosition::Right)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -42,7 +42,7 @@ impl ElementReader for TableBorders {
}
XMLElement::Bottom => {
let attr = read_border(&attributes)?;
let mut border = TableBorder::new(BorderPosition::Bottom)
let mut border = TableBorder::new(TableBorderPosition::Bottom)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -53,7 +53,7 @@ impl ElementReader for TableBorders {
}
XMLElement::Left => {
let attr = read_border(&attributes)?;
let mut border = TableBorder::new(BorderPosition::Left)
let mut border = TableBorder::new(TableBorderPosition::Left)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -64,7 +64,7 @@ impl ElementReader for TableBorders {
}
XMLElement::InsideH => {
let attr = read_border(&attributes)?;
let mut border = TableBorder::new(BorderPosition::InsideH)
let mut border = TableBorder::new(TableBorderPosition::InsideH)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -75,7 +75,7 @@ impl ElementReader for TableBorders {
}
XMLElement::InsideV => {
let attr = read_border(&attributes)?;
let mut border = TableBorder::new(BorderPosition::InsideV)
let mut border = TableBorder::new(TableBorderPosition::InsideV)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {

View File

@ -157,15 +157,15 @@ mod tests {
.width(6425, WidthType::DXA)
.grid_span(2)
.vertical_merge(VMergeType::Restart)
.set_border(TableCellBorder::new(BorderPosition::Top))
.set_border(TableCellBorder::new(BorderPosition::Left).size(3))
.set_border(TableCellBorder::new(TableCellBorderPosition::Top))
.set_border(TableCellBorder::new(TableCellBorderPosition::Left).size(3))
.set_border(
TableCellBorder::new(BorderPosition::Bottom)
TableCellBorder::new(TableCellBorderPosition::Bottom)
.size(4)
.border_type(BorderType::Double)
)
.set_border(
TableCellBorder::new(BorderPosition::InsideH)
TableCellBorder::new(TableCellBorderPosition::InsideH)
.size(5)
.color("FF0000".to_owned())
)

View File

@ -20,7 +20,7 @@ impl ElementReader for TableCellBorders {
match e {
XMLElement::Top => {
let attr = read_border(&attributes)?;
let mut border = TableCellBorder::new(BorderPosition::Top)
let mut border = TableCellBorder::new(TableCellBorderPosition::Top)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -31,7 +31,7 @@ impl ElementReader for TableCellBorders {
}
XMLElement::Right => {
let attr = read_border(&attributes)?;
let mut border = TableCellBorder::new(BorderPosition::Right)
let mut border = TableCellBorder::new(TableCellBorderPosition::Right)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -42,7 +42,7 @@ impl ElementReader for TableCellBorders {
}
XMLElement::Bottom => {
let attr = read_border(&attributes)?;
let mut border = TableCellBorder::new(BorderPosition::Bottom)
let mut border = TableCellBorder::new(TableCellBorderPosition::Bottom)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -53,7 +53,7 @@ impl ElementReader for TableCellBorders {
}
XMLElement::Left => {
let attr = read_border(&attributes)?;
let mut border = TableCellBorder::new(BorderPosition::Left)
let mut border = TableCellBorder::new(TableCellBorderPosition::Left)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -64,7 +64,7 @@ impl ElementReader for TableCellBorders {
}
XMLElement::InsideH => {
let attr = read_border(&attributes)?;
let mut border = TableCellBorder::new(BorderPosition::InsideH)
let mut border = TableCellBorder::new(TableCellBorderPosition::InsideH)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
@ -75,7 +75,29 @@ impl ElementReader for TableCellBorders {
}
XMLElement::InsideV => {
let attr = read_border(&attributes)?;
let mut border = TableCellBorder::new(BorderPosition::InsideV)
let mut border = TableCellBorder::new(TableCellBorderPosition::InsideV)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
border = border.size(size as usize);
};
borders = borders.set(border);
continue;
}
XMLElement::Tl2br => {
let attr = read_border(&attributes)?;
let mut border = TableCellBorder::new(TableCellBorderPosition::Tl2br)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {
border = border.size(size as usize);
};
borders = borders.set(border);
continue;
}
XMLElement::Tr2bl => {
let attr = read_border(&attributes)?;
let mut border = TableCellBorder::new(TableCellBorderPosition::Tr2bl)
.border_type(attr.border_type)
.color(attr.color);
if let Some(size) = attr.size {

View File

@ -77,6 +77,8 @@ pub enum XMLElement {
Bottom,
InsideH,
InsideV,
Tl2br,
Tr2bl,
TableCellMargin,
TableGrid,
GridCol,

View File

@ -1,10 +1,10 @@
use wasm_bindgen::prelude::*;
use serde::Serialize;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum BorderPosition {
pub enum TableBorderPosition {
Left,
Right,
Top,
@ -12,3 +12,17 @@ pub enum BorderPosition {
InsideH,
InsideV,
}
#[wasm_bindgen]
#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum TableCellBorderPosition {
Left,
Right,
Top,
Bottom,
InsideH,
InsideV,
Tl2br,
Tr2bl,
}

View File

@ -207,6 +207,8 @@ impl XMLBuilder {
closed_border_el!(border_right, "w:right");
closed_border_el!(border_inside_h, "w:insideH");
closed_border_el!(border_inside_v, "w:insideV");
closed_border_el!(border_tl2br, "w:tl2br");
closed_border_el!(border_tr2bl, "w:tr2bl");
closed!(shd, "w:shd", "w:fill", "w:val");

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

@ -483,67 +483,89 @@ export class Docx {
}
if (typeof c.property.borders !== "undefined") {
if (c.property.borders.top) {
const border = wasm
.createTableCellBorder(wasm.BorderPosition.Top)
.size(c.property.borders.top._size)
.color(c.property.borders.top._color)
.border_type(convertBorderType(c.property.borders.top._border_type));
cell = cell.set_border(border);
}
cell = this.buildCellBorders(c, cell);
}
if (c.property.borders.right) {
const border = wasm
.createTableCellBorder(wasm.BorderPosition.Right)
.size(c.property.borders.right._size)
.color(c.property.borders.right._color)
.border_type(
convertBorderType(c.property.borders.right._border_type)
);
cell = cell.set_border(border);
}
return cell;
}
if (c.property.borders.bottom) {
const border = wasm
.createTableCellBorder(wasm.BorderPosition.Bottom)
.size(c.property.borders.bottom._size)
.color(c.property.borders.bottom._color)
.border_type(
convertBorderType(c.property.borders.bottom._border_type)
);
cell = cell.set_border(border);
}
buildCellBorders(js: TableCell, cell: wasm.TableCell): wasm.TableCell {
if (js.property.borders.top) {
const border = wasm
.createTableCellBorder(wasm.TableCellBorderPosition.Top)
.size(js.property.borders.top._size)
.color(js.property.borders.top._color)
.border_type(convertBorderType(js.property.borders.top._border_type));
cell = cell.set_border(border);
}
if (c.property.borders.left) {
const border = wasm
.createTableCellBorder(wasm.BorderPosition.Left)
.size(c.property.borders.left._size)
.color(c.property.borders.left._color)
.border_type(convertBorderType(c.property.borders.left._border_type));
cell = cell.set_border(border);
}
if (js.property.borders.right) {
const border = wasm
.createTableCellBorder(wasm.TableCellBorderPosition.Right)
.size(js.property.borders.right._size)
.color(js.property.borders.right._color)
.border_type(convertBorderType(js.property.borders.right._border_type));
cell = cell.set_border(border);
}
if (c.property.borders.insideH) {
const border = wasm
.createTableCellBorder(wasm.BorderPosition.InsideH)
.size(c.property.borders.insideH._size)
.color(c.property.borders.insideH._color)
.border_type(
convertBorderType(c.property.borders.insideH._border_type)
);
cell = cell.set_border(border);
}
if (js.property.borders.bottom) {
const border = wasm
.createTableCellBorder(wasm.TableCellBorderPosition.Bottom)
.size(js.property.borders.bottom._size)
.color(js.property.borders.bottom._color)
.border_type(
convertBorderType(js.property.borders.bottom._border_type)
);
cell = cell.set_border(border);
}
if (c.property.borders.insideV) {
const border = wasm
.createTableCellBorder(wasm.BorderPosition.InsideV)
.size(c.property.borders.insideV._size)
.color(c.property.borders.insideV._color)
.border_type(
convertBorderType(c.property.borders.insideV._border_type)
);
cell = cell.set_border(border);
}
if (js.property.borders.left) {
const border = wasm
.createTableCellBorder(wasm.TableCellBorderPosition.Left)
.size(js.property.borders.left._size)
.color(js.property.borders.left._color)
.border_type(convertBorderType(js.property.borders.left._border_type));
cell = cell.set_border(border);
}
if (js.property.borders.insideH) {
const border = wasm
.createTableCellBorder(wasm.TableCellBorderPosition.InsideH)
.size(js.property.borders.insideH._size)
.color(js.property.borders.insideH._color)
.border_type(
convertBorderType(js.property.borders.insideH._border_type)
);
cell = cell.set_border(border);
}
if (js.property.borders.insideV) {
const border = wasm
.createTableCellBorder(wasm.TableCellBorderPosition.InsideV)
.size(js.property.borders.insideV._size)
.color(js.property.borders.insideV._color)
.border_type(
convertBorderType(js.property.borders.insideV._border_type)
);
cell = cell.set_border(border);
}
if (js.property.borders.tl2br) {
const border = wasm
.createTableCellBorder(wasm.TableCellBorderPosition.Tl2br)
.size(js.property.borders.tl2br._size)
.color(js.property.borders.tl2br._color)
.border_type(convertBorderType(js.property.borders.tl2br._border_type));
cell = cell.set_border(border);
}
if (js.property.borders.tr2bl) {
const border = wasm
.createTableCellBorder(wasm.TableCellBorderPosition.Tr2bl)
.size(js.property.borders.tr2bl._size)
.color(js.property.borders.tr2bl._color)
.border_type(convertBorderType(js.property.borders.tr2bl._border_type));
cell = cell.set_border(border);
}
return cell;

View File

@ -31,22 +31,24 @@ export type BorderType =
| "babyPacifier"
| "babyRattle";
export type BorderPosition =
export type TableCellBorderPosition =
| "left"
| "right"
| "top"
| "bottom"
| "insideH"
| "insideV";
| "insideV"
| "tl2br"
| "tr2bl";
export class TableCellBorder {
_border_type: BorderType;
_size = 2;
_color = "000000";
position: BorderPosition;
position: TableCellBorderPosition;
space = 0;
constructor(position: BorderPosition) {
constructor(position: TableCellBorderPosition) {
this.position = position;
}

View File

@ -1,4 +1,4 @@
import { BorderPosition, TableCellBorder } from "./table-cell-border";
import { TableCellBorderPosition, TableCellBorder } from "./table-cell-border";
export type PositionKeys =
| "top"
@ -6,7 +6,9 @@ export type PositionKeys =
| "bottom"
| "right"
| "insideH"
| "insideV";
| "insideV"
| "tl2br"
| "tr2bl";
export class TableCellBorders {
top: TableCellBorder | null = new TableCellBorder("top");
@ -15,6 +17,8 @@ export class TableCellBorders {
right: TableCellBorder | null = new TableCellBorder("right");
insideH: TableCellBorder | null = new TableCellBorder("insideH");
insideV: TableCellBorder | null = new TableCellBorder("insideV");
tl2br: TableCellBorder | null = null;
tr2bl: TableCellBorder | null = null;
set(border: TableCellBorder) {
switch (border.position) {
@ -30,11 +34,15 @@ export class TableCellBorders {
this.insideH = border;
case "insideV":
this.insideV = border;
case "tl2br":
this.tl2br = border;
case "tr2bl":
this.tr2bl = border;
}
return this;
}
clear(position: BorderPosition) {
clear(position: TableCellBorderPosition) {
let nil = new TableCellBorder(position).border_type("nil");
switch (position) {
case "top":
@ -49,6 +57,10 @@ export class TableCellBorders {
this.insideH = nil;
case "insideV":
this.insideV = nil;
case "tl2br":
this.tl2br = nil;
case "tr2bl":
this.tr2bl = nil;
}
return this;
}
@ -60,6 +72,8 @@ export class TableCellBorders {
this.right = new TableCellBorder("right").border_type("nil");
this.insideH = new TableCellBorder("insideH").border_type("nil");
this.insideV = new TableCellBorder("insideV").border_type("nil");
this.tl2br = new TableCellBorder("tl2br").border_type("nil");
this.tr2bl = new TableCellBorder("tr2bl").border_type("nil");
return this;
}
}

View File

@ -1,7 +1,7 @@
import { Paragraph } from "./paragraph";
import { Table } from "./table";
import { TableCellBorders, PositionKeys } from "./table-cell-borders";
import { BorderPosition, TableCellBorder } from "./table-cell-border";
import { TableCellBorderPosition, TableCellBorder } from "./table-cell-border";
import * as wasm from "./pkg";
export type VMergeType = "restart" | "continue";
@ -106,12 +106,14 @@ export class TableCell {
return this;
}
setBorder(position: BorderPosition, border: TableCellBorder) {
this.property.borders[position.toLowerCase() as PositionKeys] = border;
setBorder(border: TableCellBorder) {
this.property.borders[
border.position.toLowerCase() as PositionKeys
] = border;
return this;
}
clearBorder(position: BorderPosition) {
clearBorder(position: TableCellBorderPosition) {
this.property.borders[
position.toLowerCase() as PositionKeys
] = new TableCellBorder(position).border_type("nil");

View File

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

View File

@ -62,7 +62,7 @@ impl TableCell {
self
}
pub fn clear_border(mut self, position: docx_rs::BorderPosition) -> TableCell {
pub fn clear_border(mut self, position: docx_rs::TableCellBorderPosition) -> TableCell {
self.0.property = self.0.property.clear_border(position);
self
}

View File

@ -5,7 +5,7 @@ use wasm_bindgen::prelude::*;
pub struct TableCellBorder(docx_rs::TableCellBorder);
#[wasm_bindgen(js_name = createTableCellBorder)]
pub fn create_table_cell_border(position: docx_rs::BorderPosition) -> TableCellBorder {
pub fn create_table_cell_border(position: docx_rs::TableCellBorderPosition) -> TableCellBorder {
TableCellBorder(docx_rs::TableCellBorder::new(position))
}

View File

@ -994,6 +994,7 @@ Object {
"size": 2,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -1001,6 +1002,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": 5,
"textDirection": null,
@ -1081,6 +1083,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "single",
"color": "auto",
@ -1088,6 +1091,7 @@ Object {
"size": 4,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": 3,
"textDirection": null,
@ -1157,6 +1161,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "single",
"color": "auto",
@ -1164,6 +1169,7 @@ Object {
"size": 4,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -1244,6 +1250,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "single",
"color": "auto",
@ -1251,6 +1258,7 @@ Object {
"size": 4,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": 3,
"textDirection": null,
@ -1320,6 +1328,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "single",
"color": "auto",
@ -1327,6 +1336,7 @@ Object {
"size": 4,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -1407,6 +1417,7 @@ Object {
"size": 2,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "single",
"color": "auto",
@ -1414,6 +1425,7 @@ Object {
"size": 4,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": 2,
"textDirection": null,
@ -1483,6 +1495,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -1490,6 +1503,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -1570,6 +1584,7 @@ Object {
"size": 2,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -1577,6 +1592,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -1646,6 +1662,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "single",
"color": "auto",
@ -1653,6 +1670,7 @@ Object {
"size": 4,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": 2,
"textDirection": null,
@ -1733,6 +1751,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -1740,6 +1759,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -1809,6 +1829,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -1816,6 +1837,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -1885,6 +1907,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "single",
"color": "auto",
@ -1892,6 +1915,7 @@ Object {
"size": 4,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -1972,6 +1996,7 @@ Object {
"size": 2,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -1979,6 +2004,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -2048,6 +2074,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -2055,6 +2082,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -2124,6 +2152,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -2131,6 +2160,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -2205,6 +2235,7 @@ Object {
"size": 2,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -2212,6 +2243,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -2275,6 +2307,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -2282,6 +2315,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -2351,6 +2385,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -2358,6 +2393,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -2438,6 +2474,7 @@ Object {
"size": 2,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -2445,6 +2482,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -2514,6 +2552,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -2521,6 +2560,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -2590,6 +2630,7 @@ Object {
"size": 4,
"space": 0,
},
"tl2br": null,
"top": Object {
"borderType": "nil",
"color": "000000",
@ -2597,6 +2638,7 @@ Object {
"size": 2,
"space": 0,
},
"tr2bl": null,
},
"gridSpan": null,
"textDirection": null,
@ -10499,7 +10541,7 @@ exports[`writer should write page margin 1`] = `
exports[`writer should write page margin 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:p w14:paraId=\\"00000002\\"><w:pPr><w:rPr /></w:pPr><w:r><w:rPr><w:rFonts /></w:rPr><w:t xml:space=\\"preserve\\">Hello world!!</w:t></w:r></w:p><w:sectPr><w:pgSz w:w=\\"11906\\" w:h=\\"16838\\" /><w:pgMar w:top=\\"1000\\" w:right=\\"1701\\" w:bottom=\\"1701\\" w:left=\\"2000\\" w:header=\\"851\\" w:footer=\\"992\\" w:gutter=\\"0\\" /><w:headerReference w:type=\\"default\\" r:id=\\"rId4\\" /><w:cols w:space=\\"425\\" />
<w:body><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 world!!</w:t></w:r></w:p><w:sectPr><w:pgSz w:w=\\"11906\\" w:h=\\"16838\\" /><w:pgMar w:top=\\"1000\\" w:right=\\"1701\\" w:bottom=\\"1701\\" w:left=\\"2000\\" 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>"
@ -10538,3 +10580,35 @@ exports[`writer should write page size 3`] = `
<w:abstractNumId w:val=\\"1\\" />
</w:num></w:numbering>"
`;
exports[`writer should write tl2br and tr2bl cells 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 tl2br and tr2bl cells 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: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:tl2br w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /></w:tcBorders></w:tcPr><w:p w14:paraId=\\"00000002\\"><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: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:tr2bl w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /></w:tcBorders></w:tcPr><w:p w14:paraId=\\"00000003\\"><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: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:tl2br w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /><w:tr2bl w:val=\\"single\\" w:sz=\\"2\\" w:space=\\"0\\" w:color=\\"000000\\" /></w:tcBorders></w:tcPr><w:p w14:paraId=\\"00000004\\"><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 tl2br and tr2bl cells 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>"
`;

View File

@ -103,6 +103,37 @@ describe("writer", () => {
writeFileSync("../output/nested_table.docx", buffer);
});
test("should write tl2br and tr2bl cells", () => {
const p = new w.Paragraph().addRun(new w.Run().addText("Hello!!"));
const table = new w.Table().addRow(
new w.TableRow()
.addCell(
new w.TableCell()
.setBorder(new w.TableCellBorder("tl2br"))
.addParagraph(p)
)
.addCell(
new w.TableCell()
.setBorder(new w.TableCellBorder("tr2bl"))
.addParagraph(p)
)
.addCell(
new w.TableCell()
.setBorder(new w.TableCellBorder("tr2bl"))
.setBorder(new w.TableCellBorder("tl2br"))
.addParagraph(p)
)
);
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/cell_borders.docx", buffer);
});
test("should write page margin", () => {
const p = new w.Paragraph().addRun(new w.Run().addText("Hello world!!"));
const buffer = new w.Docx()