本文整理汇总了C#中TableCell.PrependChild方法的典型用法代码示例。如果您正苦于以下问题:C# TableCell.PrependChild方法的具体用法?C# TableCell.PrependChild怎么用?C# TableCell.PrependChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableCell
的用法示例。
在下文中一共展示了TableCell.PrependChild方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTableCell
private TableCell CreateTableCell(string contents, string cell_color = "ffffff", int width = 0)
{
// Create the TableCell object
TableCell tc = new TableCell();
TableCellProperties tcp;
if (width == 0)
{
// Create the TableCellProperties object
tcp = new TableCellProperties(
new TableCellWidth { Type = TableWidthUnitValues.Auto }
);
}
else
{
tcp = new TableCellProperties(
new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = width.ToString() }
);
}
// Create the Shading object
DocumentFormat.OpenXml.Wordprocessing.Shading shading =
new DocumentFormat.OpenXml.Wordprocessing.Shading()
{
Color = "auto",
Fill = cell_color,
Val = ShadingPatternValues.Clear
};
// Add the Shading object to the TableCellProperties object
tcp.Append(shading);
// Add the TableCellProperties object to the TableCell object
tc.PrependChild<TableCellProperties>(tcp);
// also need to ensure you include the text, otherwise it causes an error (it did for me!)
Text text = new Text(contents);
// Specify the table cell content.
Run run = new Run();
RunProperties runProp = new RunProperties(); // Create run properties.
RunFonts runFont = new RunFonts(); // Create font
runFont.Ascii = "Arial"; // Specify font family
FontSize size = new FontSize();
size.Val = new StringValue("22"); // 48 half-point font size
runProp.Append(runFont);
runProp.Append(size);
run.PrependChild<RunProperties>(runProp);
run.Append(text);
ParagraphProperties pProperties = new ParagraphProperties();
ContextualSpacing cs = new ContextualSpacing();
pProperties.Append(cs);
Paragraph paragraph = new Paragraph(run);
paragraph.PrependChild<ParagraphProperties>(pProperties);
tc.Append(paragraph);
return tc;
}