Support table cell color (#249)
* feat: Add shd writer * feat: Support shd * fix: clippy * 0.0.154main
parent
3075ffb506
commit
20361dac2d
|
@ -53,6 +53,7 @@ mod run_property;
|
|||
mod run_property_default;
|
||||
mod section;
|
||||
mod section_property;
|
||||
mod shading;
|
||||
mod spacing;
|
||||
mod start;
|
||||
mod style;
|
||||
|
@ -140,6 +141,7 @@ pub use run_property::*;
|
|||
pub use run_property_default::*;
|
||||
pub use section::*;
|
||||
pub use section_property::*;
|
||||
pub use shading::*;
|
||||
pub use spacing::*;
|
||||
pub use start::*;
|
||||
pub use style::*;
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::documents::BuildXML;
|
||||
use crate::types::*;
|
||||
use crate::xml_builder::*;
|
||||
|
||||
// INFO: Theme is not supported now.
|
||||
#[derive(Serialize, Debug, Clone, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Shading {
|
||||
pub shd_type: ShdType,
|
||||
pub color: String,
|
||||
pub fill: String,
|
||||
}
|
||||
|
||||
impl Default for Shading {
|
||||
fn default() -> Self {
|
||||
Shading {
|
||||
shd_type: ShdType::Clear,
|
||||
color: "auto".to_owned(),
|
||||
fill: "FFFFFF".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Shading {
|
||||
pub fn new() -> Shading {
|
||||
Shading::default()
|
||||
}
|
||||
|
||||
pub fn color(mut self, color: impl Into<String>) -> Shading {
|
||||
self.color = color.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn fill(mut self, fill: impl Into<String>) -> Shading {
|
||||
self.fill = fill.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn shd_type(mut self, shd_type: ShdType) -> Shading {
|
||||
self.shd_type = shd_type;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for Shading {
|
||||
fn build(&self) -> Vec<u8> {
|
||||
XMLBuilder::new()
|
||||
.shd(&self.shd_type.to_string(), &self.color, &self.fill)
|
||||
.build()
|
||||
}
|
||||
}
|
|
@ -68,6 +68,11 @@ impl TableCell {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn shading(mut self, s: Shading) -> TableCell {
|
||||
self.property = self.property.shading(s);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn vertical_align(mut self, t: VAlignType) -> TableCell {
|
||||
self.property = self.property.vertical_align(t);
|
||||
self
|
||||
|
@ -156,7 +161,10 @@ mod tests {
|
|||
#[test]
|
||||
fn test_cell() {
|
||||
let b = TableCell::new().build();
|
||||
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>"#);
|
||||
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]
|
||||
|
@ -177,7 +185,7 @@ mod tests {
|
|||
.grid_span(2);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&c).unwrap(),
|
||||
r#"{"children":[{"type":"paragraph","data":{"id":"12345678","children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"Hello"}}]}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null},"hasNumbering":false}}],"property":{"width":null,"borders":null,"gridSpan":2,"verticalMerge":null,"verticalAlign":null,"textDirection":null},"hasNumbering":false}"#
|
||||
r#"{"children":[{"type":"paragraph","data":{"id":"12345678","children":[{"type":"run","data":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null},"children":[{"type":"text","data":{"preserveSpace":true,"text":"Hello"}}]}}],"property":{"runProperty":{"sz":null,"szCs":null,"color":null,"highlight":null,"underline":null,"bold":null,"boldCs":null,"italic":null,"italicCs":null,"vanish":null,"spacing":null,"fonts":null},"style":null,"numberingProperty":null,"alignment":null,"indent":null,"lineHeight":null},"hasNumbering":false}}],"property":{"width":null,"borders":null,"gridSpan":2,"verticalMerge":null,"verticalAlign":null,"textDirection":null,"shading":null},"hasNumbering":false}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ pub struct TableCellProperty {
|
|||
vertical_merge: Option<VMerge>,
|
||||
vertical_align: Option<VAlign>,
|
||||
text_direction: Option<TextDirection>,
|
||||
shading: Option<Shading>,
|
||||
}
|
||||
|
||||
impl TableCellProperty {
|
||||
|
@ -46,6 +47,11 @@ impl TableCellProperty {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn shading(mut self, s: Shading) -> Self {
|
||||
self.shading = Some(s);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_borders(mut self, borders: TableCellBorders) -> Self {
|
||||
self.borders = Some(borders);
|
||||
self
|
||||
|
@ -76,6 +82,7 @@ impl Default for TableCellProperty {
|
|||
vertical_merge: None,
|
||||
vertical_align: None,
|
||||
text_direction: None,
|
||||
shading: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -90,6 +97,7 @@ impl BuildXML for TableCellProperty {
|
|||
.add_optional_child(&self.vertical_merge)
|
||||
.add_optional_child(&self.vertical_align)
|
||||
.add_optional_child(&self.text_direction)
|
||||
.add_optional_child(&self.shading)
|
||||
.close()
|
||||
.build()
|
||||
}
|
||||
|
@ -140,6 +148,17 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_shd() {
|
||||
let c = TableCellProperty::new()
|
||||
.shading(Shading::new().shd_type(ShdType::Clear).fill("FF0000"));
|
||||
let b = c.build();
|
||||
assert_eq!(
|
||||
str::from_utf8(&b).unwrap(),
|
||||
r#"<w:tcPr><w:shd w:val="clear" w:color="auto" w:fill="FF0000" /></w:tcPr>"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_table_cell_prop_json() {
|
||||
let c = TableCellProperty::new()
|
||||
|
@ -148,7 +167,7 @@ mod tests {
|
|||
.width(200, WidthType::DXA);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&c).unwrap(),
|
||||
r#"{"width":{"width":200,"widthType":"DXA"},"borders":null,"gridSpan":3,"verticalMerge":"continue","verticalAlign":null,"textDirection":null}"#
|
||||
r#"{"width":{"width":200,"widthType":"DXA"},"borders":null,"gridSpan":3,"verticalMerge":"continue","verticalAlign":null,"textDirection":null,"shading":null}"#
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -157,7 +176,7 @@ mod tests {
|
|||
let c = TableCellProperty::new().vertical_align(VAlignType::Center);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&c).unwrap(),
|
||||
r#"{"width":null,"borders":null,"gridSpan":null,"verticalMerge":null,"verticalAlign":"center","textDirection":null}"#
|
||||
r#"{"width":null,"borders":null,"gridSpan":null,"verticalMerge":null,"verticalAlign":"center","textDirection":null,"shading":null}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ mod tests {
|
|||
let r = TableRow::new(vec![TableCell::new()]);
|
||||
assert_eq!(
|
||||
serde_json::to_string(&r).unwrap(),
|
||||
r#"{"cells":[{"children":[],"property":{"width":null,"borders":null,"gridSpan":null,"verticalMerge":null,"verticalAlign":null,"textDirection":null},"hasNumbering":false}],"hasNumbering":false,"property":{"gridAfter":null,"widthAfter":null,"rowHeight":null,"heightRule":null}}"#
|
||||
r#"{"cells":[{"children":[],"property":{"width":null,"borders":null,"gridSpan":null,"verticalMerge":null,"verticalAlign":null,"textDirection":null,"shading":null},"hasNumbering":false}],"hasNumbering":false,"property":{"gridAfter":null,"widthAfter":null,"rowHeight":null,"heightRule":null}}"#
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ mod run;
|
|||
mod run_property;
|
||||
mod section_property;
|
||||
mod settings;
|
||||
mod shading;
|
||||
mod style;
|
||||
mod styles;
|
||||
mod table;
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
use std::io::Read;
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::types::*;
|
||||
use xml::attribute::OwnedAttribute;
|
||||
use xml::reader::EventReader;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl ElementReader for Shading {
|
||||
fn read<R: Read>(
|
||||
_r: &mut EventReader<R>,
|
||||
attrs: &[OwnedAttribute],
|
||||
) -> Result<Self, ReaderError> {
|
||||
let mut shd = Shading::new();
|
||||
for a in attrs {
|
||||
let local_name = &a.name.local_name;
|
||||
if local_name == "val" {
|
||||
if let Ok(val) = ShdType::from_str(&a.value) {
|
||||
shd = shd.shd_type(val);
|
||||
}
|
||||
} else if local_name == "color" {
|
||||
shd = shd.color(&a.value);
|
||||
} else if local_name == "fill" {
|
||||
shd = shd.fill(&a.value);
|
||||
}
|
||||
}
|
||||
Ok(shd)
|
||||
}
|
||||
}
|
|
@ -75,6 +75,11 @@ impl ElementReader for TableCell {
|
|||
)?);
|
||||
}
|
||||
}
|
||||
XMLElement::Shading => {
|
||||
if let Ok(shd) = Shading::read(r, &attributes) {
|
||||
cell = cell.shading(shd);
|
||||
}
|
||||
}
|
||||
XMLElement::TextDirection => {
|
||||
if let Some(a) = &attributes.get(0) {
|
||||
if let Ok(v) = TextDirectionType::from_str(&a.value)
|
||||
|
@ -139,7 +144,6 @@ mod tests {
|
|||
<w:insideH w:val="single" w:sz="5" w:space="0" w:color="FF0000"/>
|
||||
<w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000"/>
|
||||
</w:tcBorders>
|
||||
<w:shd w:fill="auto" w:val="clear"/>
|
||||
</w:tcPr>
|
||||
<w:p>
|
||||
<w:r>
|
||||
|
@ -179,7 +183,6 @@ mod tests {
|
|||
<w:tcPr>
|
||||
<w:tcW w:w="6425" w:type="dxa"/>
|
||||
<w:vMerge />
|
||||
<w:shd w:fill="auto" w:val="clear"/>
|
||||
</w:tcPr>
|
||||
<w:p>
|
||||
<w:r>
|
||||
|
@ -206,7 +209,6 @@ mod tests {
|
|||
<w:tcPr>
|
||||
<w:tcW w:w="6425" w:type="dxa"/>
|
||||
<w:vAlign w:val="bottom"/>
|
||||
<w:shd w:fill="auto" w:val="clear"/>
|
||||
</w:tcPr>
|
||||
<w:p>
|
||||
<w:r>
|
||||
|
|
|
@ -50,6 +50,7 @@ pub enum XMLElement {
|
|||
CommentExtended,
|
||||
CommentsExtended,
|
||||
VAlign,
|
||||
Shading,
|
||||
TextDirection,
|
||||
Table,
|
||||
TableProperty,
|
||||
|
@ -216,6 +217,7 @@ impl FromStr for XMLElement {
|
|||
"commentRangeEnd" => Ok(XMLElement::CommentRangeEnd),
|
||||
"commentEx" => Ok(XMLElement::CommentExtended),
|
||||
"commentsEx" => Ok(XMLElement::CommentsExtended),
|
||||
"shd" => Ok(XMLElement::Shading),
|
||||
"tbl" => Ok(XMLElement::Table),
|
||||
"tblPr" => Ok(XMLElement::TableProperty),
|
||||
"tr" => Ok(XMLElement::TableRow),
|
||||
|
|
|
@ -9,6 +9,7 @@ pub mod height_rule;
|
|||
pub mod level_suffix_type;
|
||||
pub mod page_margin;
|
||||
pub mod section_type;
|
||||
pub mod shd_type;
|
||||
pub mod spacing;
|
||||
pub mod special_indent_type;
|
||||
pub mod style_type;
|
||||
|
@ -29,6 +30,7 @@ pub use height_rule::*;
|
|||
pub use level_suffix_type::*;
|
||||
pub use page_margin::*;
|
||||
pub use section_type::*;
|
||||
pub use shd_type::*;
|
||||
pub use spacing::*;
|
||||
pub use special_indent_type::*;
|
||||
pub use style_type::*;
|
||||
|
|
|
@ -0,0 +1,182 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
use super::errors;
|
||||
|
||||
/*
|
||||
<xsd:enumeration value="nil"/>
|
||||
<xsd:enumeration value="clear"/>
|
||||
<xsd:enumeration value="solid"/>
|
||||
<xsd:enumeration value="horzStripe"/>
|
||||
<xsd:enumeration value="vertStripe"/>
|
||||
<xsd:enumeration value="reverseDiagStripe"/>
|
||||
<xsd:enumeration value="diagStripe"/>
|
||||
<xsd:enumeration value="horzCross"/>
|
||||
<xsd:enumeration value="diagCross"/>
|
||||
<xsd:enumeration value="thinHorzStripe"/>
|
||||
<xsd:enumeration value="thinVertStripe"/>
|
||||
<xsd:enumeration value="thinReverseDiagStripe"/>
|
||||
<xsd:enumeration value="thinDiagStripe"/>
|
||||
<xsd:enumeration value="thinHorzCross"/>
|
||||
<xsd:enumeration value="thinDiagCross"/>
|
||||
<xsd:enumeration value="pct5"/>
|
||||
<xsd:enumeration value="pct10"/>
|
||||
<xsd:enumeration value="pct12"/>
|
||||
<xsd:enumeration value="pct15"/>
|
||||
<xsd:enumeration value="pct20"/>
|
||||
<xsd:enumeration value="pct25"/>
|
||||
<xsd:enumeration value="pct30"/>
|
||||
<xsd:enumeration value="pct35"/>
|
||||
<xsd:enumeration value="pct37"/>
|
||||
<xsd:enumeration value="pct40"/>
|
||||
<xsd:enumeration value="pct45"/>
|
||||
<xsd:enumeration value="pct50"/>
|
||||
<xsd:enumeration value="pct55"/>
|
||||
<xsd:enumeration value="pct60"/>
|
||||
<xsd:enumeration value="pct62"/>
|
||||
<xsd:enumeration value="pct65"/>
|
||||
<xsd:enumeration value="pct70"/>
|
||||
<xsd:enumeration value="pct75"/>
|
||||
<xsd:enumeration value="pct80"/>
|
||||
<xsd:enumeration value="pct85"/>
|
||||
<xsd:enumeration value="pct87"/>
|
||||
<xsd:enumeration value="pct90"/>
|
||||
<xsd:enumeration value="pct95"/>
|
||||
*/
|
||||
#[wasm_bindgen]
|
||||
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||
pub enum ShdType {
|
||||
Nil,
|
||||
Clear,
|
||||
Solid,
|
||||
HorzStripe,
|
||||
VertStripe,
|
||||
ReverseDiagStripe,
|
||||
DiagStripe,
|
||||
HorzCross,
|
||||
DiagCross,
|
||||
ThinHorzStripe,
|
||||
ThinVertStripe,
|
||||
ThinReverseDiagStripe,
|
||||
ThinDiagStripe,
|
||||
ThinHorzCross,
|
||||
ThinDiagCross,
|
||||
Pct5,
|
||||
Pct10,
|
||||
Pct12,
|
||||
Pct15,
|
||||
Pct20,
|
||||
Pct25,
|
||||
Pct30,
|
||||
Pct35,
|
||||
Pct37,
|
||||
Pct40,
|
||||
Pct45,
|
||||
Pct50,
|
||||
Pct55,
|
||||
Pct60,
|
||||
Pct62,
|
||||
Pct65,
|
||||
Pct70,
|
||||
Pct75,
|
||||
Pct80,
|
||||
Pct85,
|
||||
Pct87,
|
||||
Pct90,
|
||||
Pct95,
|
||||
}
|
||||
|
||||
impl fmt::Display for ShdType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
ShdType::Nil => write!(f, "nil"),
|
||||
ShdType::Clear => write!(f, "clear"),
|
||||
ShdType::Solid => write!(f, "solid"),
|
||||
ShdType::HorzStripe => write!(f, "horzStripe"),
|
||||
ShdType::VertStripe => write!(f, "vertStripe"),
|
||||
ShdType::ReverseDiagStripe => write!(f, "reverseDiagStripe"),
|
||||
ShdType::DiagStripe => write!(f, "diagStripe"),
|
||||
ShdType::HorzCross => write!(f, "horzCross"),
|
||||
ShdType::DiagCross => write!(f, "diagCross"),
|
||||
ShdType::ThinHorzStripe => write!(f, "thinHorzStripe"),
|
||||
ShdType::ThinVertStripe => write!(f, "thinVertStripe"),
|
||||
ShdType::ThinReverseDiagStripe => write!(f, "thinReverseDiagStripe"),
|
||||
ShdType::ThinDiagStripe => write!(f, "thinDiagStripe"),
|
||||
ShdType::ThinHorzCross => write!(f, "thinHorzCross"),
|
||||
ShdType::ThinDiagCross => write!(f, "thinDiagCross"),
|
||||
ShdType::Pct5 => write!(f, "pct5"),
|
||||
ShdType::Pct10 => write!(f, "pct10"),
|
||||
ShdType::Pct12 => write!(f, "pct12"),
|
||||
ShdType::Pct15 => write!(f, "pct15"),
|
||||
ShdType::Pct20 => write!(f, "pct20"),
|
||||
ShdType::Pct25 => write!(f, "pct25"),
|
||||
ShdType::Pct30 => write!(f, "pct30"),
|
||||
ShdType::Pct35 => write!(f, "pct35"),
|
||||
ShdType::Pct37 => write!(f, "pct37"),
|
||||
ShdType::Pct40 => write!(f, "pct40"),
|
||||
ShdType::Pct45 => write!(f, "pct45"),
|
||||
ShdType::Pct50 => write!(f, "pct50"),
|
||||
ShdType::Pct55 => write!(f, "pct55"),
|
||||
ShdType::Pct60 => write!(f, "pct60"),
|
||||
ShdType::Pct62 => write!(f, "pct62"),
|
||||
ShdType::Pct65 => write!(f, "pct65"),
|
||||
ShdType::Pct70 => write!(f, "pct70"),
|
||||
ShdType::Pct75 => write!(f, "pct75"),
|
||||
ShdType::Pct80 => write!(f, "pct80"),
|
||||
ShdType::Pct85 => write!(f, "pct85"),
|
||||
ShdType::Pct87 => write!(f, "pct87"),
|
||||
ShdType::Pct90 => write!(f, "pct90"),
|
||||
ShdType::Pct95 => write!(f, "pct95"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for ShdType {
|
||||
type Err = errors::TypeError;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"nil" => Ok(ShdType::Nil),
|
||||
"clear" => Ok(ShdType::Clear),
|
||||
"solid" => Ok(ShdType::Solid),
|
||||
"horzStripe" => Ok(ShdType::HorzStripe),
|
||||
"vertStripe" => Ok(ShdType::VertStripe),
|
||||
"reverseDiagStripe" => Ok(ShdType::ReverseDiagStripe),
|
||||
"diagStripe" => Ok(ShdType::DiagStripe),
|
||||
"horzCross" => Ok(ShdType::HorzCross),
|
||||
"diagCross" => Ok(ShdType::DiagCross),
|
||||
"thinHorzStripe" => Ok(ShdType::ThinHorzStripe),
|
||||
"thinVertStripe" => Ok(ShdType::ThinVertStripe),
|
||||
"thinReverseDiagStripe" => Ok(ShdType::ThinReverseDiagStripe),
|
||||
"thinDiagStripe" => Ok(ShdType::ThinDiagStripe),
|
||||
"thinHorzCross" => Ok(ShdType::ThinHorzCross),
|
||||
"thinDiagCross" => Ok(ShdType::ThinDiagCross),
|
||||
"pct5" => Ok(ShdType::Pct5),
|
||||
"pct10" => Ok(ShdType::Pct10),
|
||||
"pct12" => Ok(ShdType::Pct12),
|
||||
"pct15" => Ok(ShdType::Pct15),
|
||||
"pct20" => Ok(ShdType::Pct20),
|
||||
"pct25" => Ok(ShdType::Pct25),
|
||||
"pct30" => Ok(ShdType::Pct30),
|
||||
"pct35" => Ok(ShdType::Pct35),
|
||||
"pct37" => Ok(ShdType::Pct37),
|
||||
"pct40" => Ok(ShdType::Pct40),
|
||||
"pct45" => Ok(ShdType::Pct45),
|
||||
"pct50" => Ok(ShdType::Pct50),
|
||||
"pct55" => Ok(ShdType::Pct55),
|
||||
"pct60" => Ok(ShdType::Pct60),
|
||||
"pct62" => Ok(ShdType::Pct62),
|
||||
"pct65" => Ok(ShdType::Pct65),
|
||||
"pct70" => Ok(ShdType::Pct70),
|
||||
"pct75" => Ok(ShdType::Pct75),
|
||||
"pct80" => Ok(ShdType::Pct80),
|
||||
"pct85" => Ok(ShdType::Pct85),
|
||||
"pct87" => Ok(ShdType::Pct87),
|
||||
"pct90" => Ok(ShdType::Pct90),
|
||||
"pct95" => Ok(ShdType::Pct95),
|
||||
_ => Err(errors::TypeError::Unknown),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -210,7 +210,7 @@ impl XMLBuilder {
|
|||
closed_border_el!(border_tl2br, "w:tl2br");
|
||||
closed_border_el!(border_tr2bl, "w:tr2bl");
|
||||
|
||||
closed!(shd, "w:shd", "w:fill", "w:val");
|
||||
closed!(shd, "w:shd", "w:val", "w:color", "w:fill");
|
||||
|
||||
closed!(tab, "w:tab");
|
||||
closed!(tab_with_pos, "w:tab", "w:val", "w:pos");
|
||||
|
|
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
|
@ -486,6 +486,10 @@ export class Docx {
|
|||
cell = this.buildCellBorders(c, cell);
|
||||
}
|
||||
|
||||
if (typeof c.property.shading !== "undefined") {
|
||||
cell = cell.shading(c.property.shading._color, c.property.shading._fill);
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
export type ShadingJSON = {
|
||||
shd_type: string | null;
|
||||
color: string;
|
||||
fill: string;
|
||||
};
|
|
@ -2,6 +2,7 @@ import { ParagraphJSON } from "./paragraph";
|
|||
import { BorderJSON } from "./border";
|
||||
import { HeightRule } from "../table-row";
|
||||
import { TextDirectionType } from "../table-cell";
|
||||
import { ShadingJSON } from "./shading";
|
||||
|
||||
export type TableCellChildJSON = ParagraphJSON;
|
||||
|
||||
|
@ -21,6 +22,7 @@ export type TableCellPropertyJSON = {
|
|||
verticalAlign: "top" | "center" | "bottom" | null;
|
||||
textDirection: TextDirectionType | null;
|
||||
hasNumbering: boolean;
|
||||
shading: ShadingJSON | null;
|
||||
};
|
||||
|
||||
export type TableRowPropertyJSON = {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
export class Shading {
|
||||
_type: string = "clear";
|
||||
_color: string = "auto";
|
||||
_fill: string = "FFFFFF";
|
||||
|
||||
color(c: string) {
|
||||
this._color = c;
|
||||
}
|
||||
|
||||
fill(c: string) {
|
||||
this._fill = c;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import { Paragraph } from "./paragraph";
|
||||
import { Table } from "./table";
|
||||
import { Shading } from "./shading";
|
||||
import { TableCellBorders, PositionKeys } from "./table-cell-borders";
|
||||
import { TableCellBorderPosition, TableCellBorder } from "./table-cell-border";
|
||||
import * as wasm from "./pkg";
|
||||
|
@ -56,6 +57,7 @@ export type CellProperty = {
|
|||
gridSpan?: number;
|
||||
width?: number;
|
||||
textDirection?: TextDirectionType;
|
||||
shading?: Shading;
|
||||
};
|
||||
|
||||
export class TableCell {
|
||||
|
@ -101,6 +103,14 @@ export class TableCell {
|
|||
return this;
|
||||
}
|
||||
|
||||
shading(color: string, fill: string) {
|
||||
const s = new Shading();
|
||||
s.color(color);
|
||||
s.fill(fill);
|
||||
this.property.shading = s;
|
||||
return this;
|
||||
}
|
||||
|
||||
textDirection(t: TextDirectionType) {
|
||||
this.property.textDirection = t;
|
||||
return this;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docx-wasm",
|
||||
"version": "0.0.153",
|
||||
"version": "0.0.154",
|
||||
"main": "dist/node/index.js",
|
||||
"browser": "dist/web/index.js",
|
||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use super::*;
|
||||
use docx_rs::Shading;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
|
@ -52,6 +53,13 @@ impl TableCell {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn shading(mut self, color: &str, fill: &str) -> TableCell {
|
||||
// INFO: Now shd_type is fixed to `clear` from js
|
||||
let s = Shading::new().color(color).fill(fill);
|
||||
self.0.property = self.0.property.shading(s);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn text_direction(mut self, t: docx_rs::TextDirectionType) -> TableCell {
|
||||
self.0.property = self.0.property.text_direction(t);
|
||||
self
|
||||
|
|
|
@ -1003,6 +1003,7 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": 5,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -1092,6 +1093,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": 3,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": "center",
|
||||
"verticalMerge": "restart",
|
||||
|
@ -1170,6 +1176,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": "center",
|
||||
"verticalMerge": "restart",
|
||||
|
@ -1259,6 +1270,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": 3,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": "center",
|
||||
"verticalMerge": "continue",
|
||||
|
@ -1337,6 +1353,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": "center",
|
||||
"verticalMerge": "continue",
|
||||
|
@ -1426,6 +1447,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": 2,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -1504,6 +1530,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -1593,6 +1624,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -1671,6 +1707,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": 2,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -1760,6 +1801,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -1838,6 +1884,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -1916,6 +1967,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -2005,6 +2061,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -2083,6 +2144,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -2161,6 +2227,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -2244,6 +2315,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -2316,6 +2392,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -2394,6 +2475,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -2483,6 +2569,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -2561,6 +2652,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -2639,6 +2735,11 @@ Object {
|
|||
"tr2bl": null,
|
||||
},
|
||||
"gridSpan": null,
|
||||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9223,6 +9324,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9268,6 +9370,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9313,6 +9416,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9358,6 +9462,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9414,6 +9519,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9459,6 +9565,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9504,6 +9611,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9549,6 +9657,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9605,6 +9714,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9650,6 +9760,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9695,6 +9806,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -9740,6 +9852,7 @@ Object {
|
|||
"property": Object {
|
||||
"borders": null,
|
||||
"gridSpan": null,
|
||||
"shading": null,
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
"verticalMerge": null,
|
||||
|
@ -10362,6 +10475,38 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`writer should write cell shading 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 cell shading 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:tcBorders><w:shd w:val=\\"clear\\" w:color=\\"auto\\" w:fill=\\"FF0000\\" /></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 cell shading 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 default font 1`] = `
|
||||
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
|
||||
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
|
||||
|
|
|
@ -134,6 +134,23 @@ describe("writer", () => {
|
|||
writeFileSync("../output/cell_borders.docx", buffer);
|
||||
});
|
||||
|
||||
test("should write cell shading", () => {
|
||||
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).shading("auto", "FF0000")
|
||||
)
|
||||
);
|
||||
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_shading.docx", buffer);
|
||||
});
|
||||
|
||||
test("should write page margin", () => {
|
||||
const p = new w.Paragraph().addRun(new w.Run().addText("Hello world!!"));
|
||||
const buffer = new w.Docx()
|
||||
|
|
Loading…
Reference in New Issue