本文整理汇总了C#中OpenXmlElement.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlElement.Descendants方法的具体用法?C# OpenXmlElement.Descendants怎么用?C# OpenXmlElement.Descendants使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlElement
的用法示例。
在下文中一共展示了OpenXmlElement.Descendants方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeElementUsage
private void AnalyzeElementUsage(OpenXmlElement element)
{
if (element != null)
{
this.UpdateElementUsage(element);
foreach (var childElement in element.Descendants())
{
this.UpdateElementUsage(childElement);
}
}
}
示例2: GetMergeRuns
public static IEnumerable<MergeField> GetMergeRuns(OpenXmlElement element)
{
// Gets each element under the element with text representing a merge field.
foreach (var run in element.Descendants<Run>())
{
if (run.InnerText.StartsWith(MergeField.StartMergeField.ToString())
&& run.InnerText.EndsWith(MergeField.EndMergeField.ToString()))
{
yield return ConvertRunToMergeField(run);
}
}
}
示例3: AssignSectionProperties
/// <summary>
/// Assigns the section properties.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="secProperties">The sec properties.</param>
private static void AssignSectionProperties(OpenXmlCompositeElement document, OpenXmlElement secProperties)
{
if (document == null)
{
throw new ArgumentNullException("document");
}
if (secProperties == null)
{
return;
}
var pageSize = secProperties.Descendants<PageSize>().FirstOrDefault();
if (pageSize != null)
{
pageSize.Remove();
}
var pageMargin = secProperties.Descendants<PageMargin>().FirstOrDefault();
if (pageMargin != null)
{
pageMargin.Remove();
}
document.AppendChild(new Paragraph(new ParagraphProperties(new SectionProperties(pageSize, pageMargin))));
}
示例4: UpdatePowerPointBlock
private static void UpdatePowerPointBlock(ReportData client, OpenXmlPartContainer container, OpenXmlElement block, TableDefinition content, Dictionary<string, string> options)
{
if (null != content && block is OXP.GraphicFrame)
{
OXD.Table initTable = (OXD.Table)block.Descendants<OXD.Table>().FirstOrDefault();
if (null != initTable)
{
try
{
OXD.Table table = initTable.CloneNode(true) as OXD.Table;
OXD.TableRow headerRowTemplate = table.Descendants<OXD.TableRow>().First().CloneNode(true) as OXD.TableRow;
OXD.TableRow contentRowTemplate = table.Descendants<OXD.TableRow>().Skip(1).First().CloneNode(true) as OXD.TableRow;
ModifyPowerPointRowTextContent(headerRowTemplate, string.Empty);
ModifyPowerPointRowTextContent(contentRowTemplate, string.Empty);
#region Column Number Management
List<OXD.GridColumn> columns = table.TableGrid.Descendants<OXD.GridColumn>().ToList();
if (columns.Count < content.NbColumns)
{
int nbNewColumn = content.NbColumns - columns.Count;
for (int i = 0, lim = nbNewColumn; i < lim; i++)
{
AddNewGridColumn(table.TableGrid, headerRowTemplate, contentRowTemplate);
}
} else if (columns.Count > content.NbColumns) {
for (int i = content.NbColumns, lim = columns.Count; i < lim; i++) {
RemoveLastGridColumn(table.TableGrid);
}
}
#endregion Column Number Management
int idx = 0;
int nbrow = 0;
List<OXD.TableCell> headerCells = headerRowTemplate.Descendants<OXD.TableCell>().Select(_ => _.CloneNode(true) as OXD.TableCell).ToList();
List<OXD.TableCell> contentCells = contentRowTemplate.Descendants<OXD.TableCell>().Select(_ => _.CloneNode(true) as OXD.TableCell).ToList();
headerRowTemplate.RemoveAllChildren<OXD.TableCell>();
OXD.TableRow row = headerRowTemplate;
table.RemoveAllChildren<OXD.TableRow>();
foreach (var item in content.Data)
{
OXD.TableCell cell = null;
if (content.HasColumnHeaders && 0 == nbrow)
{
cell = headerCells[idx].CloneNode(true) as OXD.TableCell;
}
else
{
cell = contentCells[idx].CloneNode(true) as OXD.TableCell;
}
ModifyPowerPointCellTextContent(cell, item);
//row.Append(cell); => in office 2016, element <extLst> should absolutely be in the latest position in a row
row.InsertBefore<OXD.TableCell>(cell, row.Descendants<OXD.ExtensionList>().FirstOrDefault());
idx = ++idx % content.NbColumns;
if (0 == idx)
{
if (null != row)
{
table.Append(row);
nbrow++;
}
row = contentRowTemplate.CloneNode(true) as OXD.TableRow;
row.RemoveAllChildren<OXD.TableCell>();
}
}
initTable.Parent.ReplaceChild(table, initTable);
}
catch (Exception exception)
{
LogHelper.Instance.LogErrorFormat("An unhandled exception was thrown during table block content generation : '{0}'", exception.ToString());
if (null != initTable)
{
if (null != initTable.Descendants<OXD.TableRow>() && 1 > initTable.Descendants<OXD.TableRow>().Count())
{
foreach (var row in initTable.Descendants<OXD.TableRow>().Skip(1))
{
ModifyPowerPointRowTextContent(row, string.Empty);
}
}
}
}
}
}
else
{
LogHelper.Instance.LogErrorFormat("Impossible to load data in table block with a block source of type \"{0}\"", null != block ? block.GetType().ToString() : "null");
}
}
示例5: SetVisibilityInParagraphRuns
private static void SetVisibilityInParagraphRuns(OpenXmlElement paragraph, bool visible)
{
var runsInParagraph = paragraph.Descendants().OfType<Run>().ToList();
foreach (var run in runsInParagraph)
{
if (IsPlaceholder(run))
{
Hide(run);
continue;
}
if (visible)
run.RunProperties.Vanish = null;
else if (run.RunProperties.Vanish == null)
Hide(run);
}
}
示例6: SetVisibilityInParagraphProperty
private static void SetVisibilityInParagraphProperty(OpenXmlElement paragraph, bool visible)
{
var markRunProperties = paragraph.Descendants()
.OfType<ParagraphProperties>()
.SelectMany(paragraphProperty => paragraphProperty.Descendants())
.OfType<ParagraphMarkRunProperties>()
.ToList();
foreach (var markRunProperty in markRunProperties)
{
markRunProperty.RemoveAllChildren<Vanish>();
if (!visible)
markRunProperty.Append(new Vanish());
}
}
示例7: ClonePageAndFill
private static void ClonePageAndFill(DataRowView drv, OpenXmlElement item, ref OpenXmlElement addItem, SimplePropertyCollection templateSimples)
{
foreach (SdtElement sdtElement in item.Descendants<SdtElement>())
{
foreach (SdtAlias ite11 in sdtElement.Descendants<SdtAlias>())
{
DCTSimpleProperty temSimple = templateSimples[ite11.Val];
if (temSimple != null)
{
var items = sdtElement.Descendants<Run>();
if (items.Count() > 0)
{
Run runElement = items.First();
runElement.RemoveAllChildren<Text>();
runElement.AppendChild<Text>(new Text(GeneralFormatter.ToString(drv[temSimple.TagID], temSimple.FormatString)));
if (temSimple.IsReadOnly)
{
Lock lockControl = new Lock();
lockControl.Val = LockingValues.SdtContentLocked;
sdtElement.SdtProperties.Append(lockControl);
}
}
}
}
}
}
示例8: GetRunsFromElement
/// <summary>
/// Возвращает список OXMLRunWrap из всего (!) переданного дерева
/// </summary>
/// <param name="elem">корневой элемент дерева</param>
/// <returns>Список OXMLRunWrap</returns>
public static List<OXMLRunWrap> GetRunsFromElement(OpenXmlElement elem)
{
var result = new List<OXMLRunWrap>();
if (elem == null) return result;
result.AddRange( elem.Descendants<Run>().Select(x => new OXMLRunWrap(x) ) );
return result;
}