private static TableCell SetupCell(string text, bool center = false) { try { TableCell tableCell = new TableCell(); TableCellProperties tableCellProperties = new TableCellProperties(); // border & padding TableCellBorders borders = new TableCellBorders(); TopBorder topBorder = new TopBorder { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "A1A2A3" }; borders.AppendChild(topBorder); BottomBorder bottomBorder = new BottomBorder { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "A1A2A3" }; borders.AppendChild(bottomBorder); RightBorder rightBorder = new RightBorder { Val = new EnumValue <BorderValues>(BorderValues.Nil) }; borders.AppendChild(rightBorder); LeftBorder leftBorder = new LeftBorder { Val = new EnumValue <BorderValues>(BorderValues.Nil) }; borders.AppendChild(leftBorder); TableCellMargin margin = new TableCellMargin(); TopMargin topMargin = new TopMargin() { Width = "40" }; BottomMargin bottomMargin = new BottomMargin() { Width = "40" }; margin.AppendChild(topMargin); margin.AppendChild(bottomMargin); tableCellProperties.AppendChild(borders); tableCellProperties.AppendChild(margin); tableCell.AppendChild(tableCellProperties); // add text (with specific formatting) Paragraph paragraph = new Paragraph() { RsidParagraphAddition = "00607D74", RsidRunAdditionDefault = "00607D74", ParagraphId = "6ED85602", TextId = "77777777" }; ParagraphProperties paragraphProperties = new ParagraphProperties(); ParagraphMarkRunProperties paragraphMarkRunProperties = new ParagraphMarkRunProperties(); paragraphMarkRunProperties.AppendChild(new Color { Val = "000000" }); paragraphMarkRunProperties.AppendChild(new RunFonts { Ascii = "Arial" }); paragraphMarkRunProperties.AppendChild(new FontSize() { Val = "7pt" }); Justification justification = new Justification() { Val = JustificationValues.Left }; if (center) { justification.Val = JustificationValues.Center; } paragraphProperties.AppendChild(paragraphMarkRunProperties); paragraphProperties.AppendChild(justification); paragraph.AppendChild(paragraphProperties); paragraph.AppendChild(new Text(text)); // add to table cell tableCell.AppendChild(paragraph); return(tableCell); } catch (Exception e) { Console.WriteLine(e); throw; } }
private static TableCell SetupHeaderCell(string text, string width, bool center = false) { try { TableCell tableCell = new TableCell(); TableCellProperties tableCellProperties = new TableCellProperties(); TableCellWidth tableCellWidth = new TableCellWidth() { Width = width, Type = TableWidthUnitValues.Dxa }; Shading shading = new Shading() { Val = ShadingPatternValues.Clear, Fill = "FFFFFF", Color = "auto" }; // border & padding TableCellBorders borders = new TableCellBorders(); TopBorder topBorder = new TopBorder { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "000000" }; borders.AppendChild(topBorder); BottomBorder bottomBorder = new BottomBorder { Val = new EnumValue <BorderValues>(BorderValues.Thick), Color = "000000" }; borders.AppendChild(bottomBorder); TableCellMargin margin = new TableCellMargin(); TopMargin topMargin = new TopMargin() { Width = "40" }; BottomMargin bottomMargin = new BottomMargin() { Width = "40" }; margin.AppendChild(topMargin); margin.AppendChild(bottomMargin); tableCellProperties.AppendChild(tableCellWidth); tableCellProperties.AppendChild(shading); tableCellProperties.AppendChild(borders); tableCellProperties.AppendChild(margin); tableCellProperties.AppendChild(new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center }); tableCell.AppendChild(tableCellProperties); // add text (with specific formatting) Paragraph paragraph = new Paragraph() { RsidParagraphAddition = "00607D74", RsidRunAdditionDefault = "00607D74", ParagraphId = "6ED85602", TextId = "77777777" }; ParagraphProperties paragraphProperties = new ParagraphProperties(); ParagraphMarkRunProperties paragraphMarkRunProperties = new ParagraphMarkRunProperties(); paragraphMarkRunProperties.AppendChild(new Color { Val = "000000" }); paragraphMarkRunProperties.AppendChild(new RunFonts { Ascii = "Arial" }); paragraphMarkRunProperties.AppendChild(new FontSize() { Val = "8pt" }); paragraphMarkRunProperties.AppendChild(new Bold()); Justification justification = new Justification() { Val = JustificationValues.Left }; if (center) { justification.Val = JustificationValues.Center; } paragraphProperties.AppendChild(paragraphMarkRunProperties); paragraphProperties.AppendChild(justification); paragraph.AppendChild(paragraphProperties); paragraph.AppendChild(new Text(text)); // add to table cell tableCell.AppendChild(paragraph); return(tableCell); } catch (Exception e) { Console.WriteLine(e); throw; } }