本文整理汇总了C#中TableCell.Elements方法的典型用法代码示例。如果您正苦于以下问题:C# TableCell.Elements方法的具体用法?C# TableCell.Elements怎么用?C# TableCell.Elements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TableCell
的用法示例。
在下文中一共展示了TableCell.Elements方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRow
public static void AddRow(this Table table, string[] cells, string[] styles = null, bool singleSpace = true)
{
TableRow tr = new TableRow();
for (int i = 0; i < cells.Length; i++)
{
TableCell tc = new TableCell();
if(cells[i].Contains("|"))
{
Paragraph para = tc.AppendChild(new Paragraph(new ParagraphProperties()));
Run run = para.AppendChild(new Run(new RunProperties()));
string[] values = cells[i].Split('|');
for(int j = 0, jj = values.Length; j < jj; j++)
{
if(j != 0)
run.AppendChild(new Break());
run.AppendChild(new Text(values[j]));
}
}
else
tc.AppendChild(new Paragraph(new ParagraphProperties(), new Run(new RunProperties(), new Text(cells[i]))));
tr.Append(tc);
foreach (OpenXmlElement els in tc.Elements())
{
if (els.GetType() == typeof(Paragraph))
{
Paragraph para = (Paragraph)els;
if(singleSpace)
para.ParagraphProperties.AppendChild(new SpacingBetweenLines() { Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0" });
else
para.ParagraphProperties.AppendChild(new SpacingBetweenLines() { Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "240", After = "0" });
}
}
if (styles != null && styles.Length > i && !string.IsNullOrEmpty(styles[i]))
{
TableCellProperties props = new TableCellProperties();
tc.Append(props);
if (styles[i].Contains("LeftIndent"))
{
string value = styles[i].Substring(styles[i].IndexOf("LeftIndent:") + 11);
if (value.Contains("|"))
value = value.Substring(0, value.IndexOf("|"));
props.LeftIndent(value);
}
if (styles[i].Contains("RightIndent"))
{
string value = styles[i].Substring(styles[i].IndexOf("RightIndent:") + 12);
if (value.Contains("|"))
value = value.Substring(0, value.IndexOf("|"));
props.RightIndent(value);
}
if (styles[i].Contains("TopIndent"))
{
string value = styles[i].Substring(styles[i].IndexOf("TopIndent:") + 10);
if (value.Contains("|"))
value = value.Substring(0, value.IndexOf("|"));
props.TopIndent(value);
}
if (styles[i].Contains("Background"))
{
string value = styles[i].Substring(styles[i].IndexOf("Background:") + 11);
if (value.Contains("|"))
value = value.Substring(0, value.IndexOf("|"));
props.BackgroundColor(value);
}
if (styles[i].Contains("Bold"))
tc.Bold();
if (styles[i].Contains("JustifyRight"))
tc.Right();
if (styles[i].Contains("JustifyCenter"))
tc.Center();
if(styles[i].Contains("FontSize"))
{
string value = styles[i].Substring(styles[i].IndexOf("FontSize:") + 9);
if (value.Contains("|"))
value = value.Substring(0, value.IndexOf("|"));
tc.FontSize(value);
}
if (styles[i].Contains("FontColor"))
{
string value = styles[i].Substring(styles[i].IndexOf("FontColor:") + 10);
if (value.Contains("|"))
value = value.Substring(0, value.IndexOf("|"));
tc.FontColor(value);
}
if (styles[i].Contains("VerticalText"))
{
string value = styles[i].Substring(styles[i].IndexOf("VerticalText:") + 13);
if (value.Contains("|"))
value = value.Substring(0, value.IndexOf("|"));
props.VerticalText(value);
}
if (styles[i].Contains("Borders"))
{
string value = styles[i].Substring(styles[i].IndexOf("Borders:") + 8);
if (value.Contains("|"))
value = value.Substring(0, value.IndexOf("|"));
//.........这里部分代码省略.........
示例2: ProcessTd
private void ProcessTd(int colIndex, DocxNode td, TableRow row, DocxTableProperties tableProperties)
{
TableCell cell = new TableCell();
bool hasRowSpan = false;
string rowSpan = td.ExtractAttributeValue(DocxTableProperties.rowSpan);
Int32 rowSpanValue;
if (Int32.TryParse(rowSpan, out rowSpanValue))
{
tableProperties.RowSpanInfo[colIndex] = rowSpanValue - 1;
hasRowSpan = true;
}
DocxTableCellStyle style = new DocxTableCellStyle();
style.HasRowSpan = hasRowSpan;
style.Process(cell, tableProperties, td);
if (td.HasChildren)
{
Paragraph para = null;
//If the cell is th header, apply font-weight:bold to the text
if (tableProperties.IsCellHeader)
{
SetThStyleToRun(td);
}
foreach (DocxNode child in td.Children)
{
td.CopyExtentedStyles(child);
if (child.IsText)
{
if (!IsEmptyText(child.InnerHtml))
{
if (para == null)
{
para = cell.AppendChild(new Paragraph());
OnParagraphCreated(DocxTableCellStyle.GetHtmlNodeForTableCellContent(td), para);
}
Run run = para.AppendChild(new Run(new Text()
{
Text = ClearHtml(child.InnerHtml),
Space = SpaceProcessingModeValues.Preserve
}));
RunCreated(child, run);
}
}
else
{
child.ParagraphNode = DocxTableCellStyle.GetHtmlNodeForTableCellContent(td);
child.Parent = cell;
td.CopyExtentedStyles(child);
ProcessChild(child, ref para);
}
}
}
//The last element of the table cell must be a paragraph.
var lastElement = cell.Elements().LastOrDefault();
if (lastElement == null || !(lastElement is Paragraph))
{
cell.AppendChild(new Paragraph());
}
row.Append(cell);
}