本文整理汇总了C#中OpenXmlElement.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlElement.GetType方法的具体用法?C# OpenXmlElement.GetType怎么用?C# OpenXmlElement.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlElement
的用法示例。
在下文中一共展示了OpenXmlElement.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetProperties
/// <summary>
/// Insert a style element inside a RunProperties, taking care of the correct sequence order as defined in the ECMA Standard.
/// </summary>
/// <param name="containerProperties">A RunProperties or ParagraphProperties wherein the tag will be inserted.</param>
/// <param name="tag">The style to apply to the run.</param>
protected void SetProperties(OpenXmlCompositeElement containerProperties, OpenXmlElement tag)
{
// This implementation is largely inspired by DocumentFormat.OpenXml.OpenXmlCompositeElement.SetElement which is internal.
int tagOrder = GetTagOrder(tag);
OpenXmlElement firstChild = containerProperties.FirstChild;
OpenXmlElement openXmlElement = null;
Type type = tag.GetType();
while (firstChild != null)
{
bool isKnownElement = (!(firstChild is OpenXmlUnknownElement) && !(firstChild is OpenXmlMiscNode));
if (isKnownElement)
{
int num = GetTagOrder(firstChild);
if (num != tagOrder)
{
if (num > tagOrder) break;
openXmlElement = firstChild;
}
else if (!type.IsInstanceOfType(tag))
{
openXmlElement = firstChild;
}
else
{
openXmlElement = firstChild.PreviousSibling();
containerProperties.RemoveChild<OpenXmlElement>(firstChild);
break;
}
}
firstChild = firstChild.NextSibling();
}
if (tag != null)
containerProperties.InsertAfter(tag, openXmlElement);
}
示例2: 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");
}
}
示例3: 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");
}
}
示例4: UpdateElementUsage
private void UpdateElementUsage(OpenXmlElement element)
{
string elementType = element.GetType().FullName;
if (this.elementUsage.Contains(elementType) == false)
{
this.elementUsage.Add(elementType);
}
if (this.elementUsageInPackage.Contains(elementType) == false)
{
this.elementUsageInPackage.Add(elementType);
}
}