本文整理汇总了C#中OpenXmlElement.Elements方法的典型用法代码示例。如果您正苦于以下问题:C# OpenXmlElement.Elements方法的具体用法?C# OpenXmlElement.Elements怎么用?C# OpenXmlElement.Elements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenXmlElement
的用法示例。
在下文中一共展示了OpenXmlElement.Elements方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPlainText
private string GetPlainText(OpenXmlElement element)
{
StringBuilder PlainTextInWord = new StringBuilder();
foreach (OpenXmlElement section in element.Elements())
{
switch (section.LocalName)
{
// Text
case "t":
PlainTextInWord.Append(section.InnerText);
break;
case "cr": // Carriage return
case "br": // Page break
PlainTextInWord.Append(Environment.NewLine);
break;
// Tab
case "tab":
PlainTextInWord.Append("\t");
break;
// Paragraph
case "p":
PlainTextInWord.Append(GetPlainText(section));
PlainTextInWord.AppendLine(Environment.NewLine);
break;
default:
PlainTextInWord.Append(GetPlainText(section));
break;
}
}
return PlainTextInWord.ToString();
}
示例2: ExtractTextFromWordDocument
//used by the method above
private static List<String> ExtractTextFromWordDocument(OpenXmlElement element)
{
List<String> DocumentStructureList = new List<String>();
foreach (OpenXmlElement section in element.Elements())
{
switch (section.LocalName)
{
// Text
case "t":
if (section.InnerText.StartsWith("%Math-&") || section.InnerText.StartsWith("%Image-&") || section.InnerText.StartsWith("%Table-&") ||
section.InnerText.StartsWith("%h1-&") ||
section.InnerText.StartsWith("%h2-&") ||
section.InnerText.StartsWith("%h3-&") ||
section.InnerText.StartsWith("%h4-&") ||
section.InnerText.StartsWith("%h5-&") ||
section.InnerText.StartsWith("%title-&") ||
section.InnerText.StartsWith("%subtitle-&"))
{
string s1 = AddTextToTextList();
if (s1 != null)
DocumentStructureList.Add(s1);
DocumentStructureList.Add(section.InnerText);
}
else
{
textBuilder.Append(section.InnerText);
}
break;
case "cr": // Carriage return
case "br": // Page break
string s4 = AddTextToTextList();
if (s4 != null)
DocumentStructureList.Add(s4);
break;
// Tab
case "tab":
textBuilder.Append("\t");
break;
// Paragraph
case "p":
string s3 = AddTextToTextList();
if (s3 != null)
DocumentStructureList.Add(s3);
DocumentStructureList.AddRange(ExtractTextFromWordDocument(section));
break;
case "pict":
case "drawing":
break;
case "pgNum": break;
case "sym": break;
default:
DocumentStructureList.AddRange(ExtractTextFromWordDocument(section));
break;
}
}
return DocumentStructureList;
}
示例3: AdjustRow
private static IEnumerable<Cell> AdjustRow(OpenXmlElement row, int capacity)
{
if (row == null)
return new Cell[] {};
var cells = row.Elements<Cell>();
var list = new Cell[capacity];
foreach (var cell in cells)
{
var index = ExcelUtil.GetColumnIndexByName(cell.CellReference.Value);
if (index < capacity)
list[index] = cell;
}
return list;
}
示例4: FindBookmarks
private static Dictionary<string, BookmarkEnd> FindBookmarks(OpenXmlElement documentPart, Dictionary<string, BookmarkEnd> results = null, Dictionary<string, string> unmatched = null)
{
results = results ?? new Dictionary<string, BookmarkEnd>();
unmatched = unmatched ?? new Dictionary<string, string>();
foreach (var child in documentPart.Elements())
{
if (child is BookmarkStart)
{
var bStart = child as BookmarkStart;
unmatched.Add(bStart.Id, bStart.Name);
}
if (child is BookmarkEnd)
{
var bEnd = child as BookmarkEnd;
foreach (var orphanName in unmatched)
{
if (bEnd.Id == orphanName.Key)
results.Add(orphanName.Value, bEnd);
}
}
FindBookmarks(child, results, unmatched);
}
return results;
}