public void Write(XElement parent) { XNamespace ns = parent.Name.Namespace; XElement table = new XElement(ns + "tbl"); parent.Add(table); XElement props = new XElement(ns + "tblPr"); table.Add(props); XElement algorithm = new XElement( ns + "tblLayout", new XAttribute(ns + "type", "fixed")); props.Add(algorithm); XElement width = StyleHelpers.CreateWidth(ns, "tblW", _width); props.Add(width); XElement grid = new XElement(ns + "tblGrid"); props.Add(grid); foreach (int columnWidth in _columnWidths) { XElement column = new XElement( ns + "gridCol", new XAttribute(ns + "w", columnWidth)); grid.Add(column); } XElement border = StyleHelpers.CreateBorder(ns, "tblBorders", _style?.Border, _style?.Padding); if (border != null) { props.Add(border); } foreach (TableRow row in _rows) { row.Write(table); } }
public void Write(XElement parent) { XNamespace ns = parent.Name.Namespace; XElement para = new XElement(ns + "p"); parent.Add(para); XElement props = new XElement(ns + "pPr"); para.Add(props); if (_numberingId > -1) { XElement numPr = new XElement(ns + "numPr"); props.Add(numPr); XElement ilvl = new XElement( ns + "ilvl", new XAttribute(ns + "val", _numberingLevel)); numPr.Add(ilvl); XElement numId = new XElement( ns + "numId", new XAttribute(ns + "val", _numberingId)); numPr.Add(numId); } string align = null; switch (_style.Alignment) { case s.TextAlignment.Left: align = "start"; break; case s.TextAlignment.Right: align = "end"; break; case s.TextAlignment.Center: align = "center"; break; case s.TextAlignment.Justify: align = "both"; break; } if (align != null) { XElement prop = new XElement( ns + "jc", new XAttribute(ns + "val", align)); props.Add(prop); } //TODO: keepLines, keepNext, pageBreakBefore XElement border = StyleHelpers.CreateBorder(ns, "pBdr", _style.Border, _style.Padding); if (border != null) { props.Add(border); } if (_style.BackColor != null) { int red = (int)(_style.BackColor.Red * 255f); int green = (int)(_style.BackColor.Green * 255f); int blue = (int)(_style.BackColor.Blue * 255f); string color = $"{red:X2}{green:X2}{blue:X2}"; XElement shd = new XElement( ns + "shd", new XAttribute(ns + "fill", color)); props.Add(shd); } foreach (IParagraphContent content in _content) { content.Write(para); } }