本文整理汇总了C#中OpenXmlElement.Ancestors方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlElement.Ancestors方法的具体用法?C# OpenXmlElement.Ancestors怎么用?C# OpenXmlElement.Ancestors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlElement
的用法示例。
在下文中一共展示了OpenXmlElement.Ancestors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateWordBlock
private static void UpdateWordBlock(ReportData client, OpenXmlPartContainer container, OpenXmlElement block, TableDefinition content, Dictionary<string, string> options)
{
if (null != content && block is OXW.Table)
{
OXW.Table table = ((OXW.Table)block).CloneNode(true) as OXW.Table;
OXW.TableRow headerRowTemplate = table.Descendants<OXW.TableRow>().First().CloneNode(true) as OXW.TableRow;
OXW.TableRow contentRowTemplate = table.Descendants<OXW.TableRow>().Skip(1).First().CloneNode(true) as OXW.TableRow;
#region Column number management
OXW.TableGrid tablegrid = table.Descendants<OXW.TableGrid>().FirstOrDefault();
if (null != tablegrid)
{
List<OXW.GridColumn> columns = tablegrid.Descendants<OXW.GridColumn>().ToList();
if (null != columns && content.NbColumns != columns.Count)
{
if (content.NbColumns < columns.Count)
{
for (int i = columns.Count - 1, lim = content.NbColumns - 1; i > lim; i--)
{
tablegrid.RemoveChild<OXW.GridColumn>(columns[i]);
}
}
else
{
for (int i = 0, lim = content.NbColumns - columns.Count; i < lim; i++)
{
tablegrid.AppendChild<OXW.GridColumn>(new OXW.GridColumn() { Width = "1000" });
}
}
}
}
#endregion Column number management
ModifyWordRowTextContent(headerRowTemplate, string.Empty);
ModifyWordRowTextContent(contentRowTemplate, string.Empty);
int idx = 0;
int nbrow = 0;
List<OXW.TableCell> headerCells = headerRowTemplate.Descendants<OXW.TableCell>().Select(_ => _.CloneNode(true) as OXW.TableCell).ToList();
List<OXW.TableCell> contentCells = contentRowTemplate.Descendants<OXW.TableCell>().Select(_ => _.CloneNode(true) as OXW.TableCell).ToList();
headerRowTemplate.RemoveAllChildren<OXW.TableCell>();
OXW.TableRow row = headerRowTemplate;
int headerCellsCount = headerCells.Count;
int contentCellsCount = headerCells.Count;
table.RemoveAllChildren<OXW.TableRow>();
foreach (var item in content.Data)
{
if (null != item)
{
OXW.TableCell cell = null;
if (content.HasColumnHeaders && 0 == nbrow)
{
cell = headerCells[idx % headerCellsCount].CloneNode(true) as OXW.TableCell;
}
else
{
cell = contentCells[idx % contentCellsCount].CloneNode(true) as OXW.TableCell;
}
ModifyWordCellTextContent(cell, item);
row.Append(cell);
}
idx = ++idx % content.NbColumns;
if (0 == idx)
{
if (null != row)
{
table.Append(row);
nbrow++;
}
row = contentRowTemplate.CloneNode(true) as OXW.TableRow;
row.RemoveAllChildren<OXW.TableCell>();
}
}
var blockSdt = block.Ancestors<OXW.SdtBlock>().First();
blockSdt.Parent.ReplaceChild(table, blockSdt);
}
else
{
LogHelper.Instance.LogErrorFormat("Impossible to load data in Table block with a block source of type \"{0}\"", null != block ? block.GetType().ToString() : "null");
}
}