查找段落的枚举 [英] Finding the enumeration of a paragraph
问题描述
你好,
我有一个相当棘手的问题。我需要在段落前面找到枚举符号,比如
1)这是第一行
2)这是第二行
在这种情况下,1)和2)不包含在段落本身中,而是隐藏在其他地方。
有没有办法获得这个信息?
亲切的问候,
Simon
我建议您使用Open Xml PowerTools快速检索列表段落。
你可以从NuGet获得它。
有关Open Xml PowerTools的更多信息,请访问<跨度>&NBSP;
https://github.com/OfficeDev / Open-Xml-PowerTools
Screen-Cast:WordprocessingML编号 如何
使用ListItemRetriever。
有关编号列表的更多信息,请访问
使用Open XML WordprocessingML中的编号列表
例如
使用DocumentFormat.OpenXml.Packaging;
使用DocumentFormat.OpenXml.Wordprocessing;
使用System.Xml.Linq;
使用OpenXmlPowerTools;
using(WordprocessingDocument doc = WordprocessingDocument.Open(fileName,false))
{
MainDocumentPart mdp = doc.MainDocumentPart;
XDocument xDoc = mdp.GetXDocument();
var paras = xDoc.Descendants(W.p);
foreach(var para in para)
{
string listItem = ListItemRetriever.RetrieveListItem(doc,para,null);
string paraText = para.Descendants(W.t).Select(t =>(string)t).StringConcatenate();
Console.WriteLine(" List Item:{0} Paragraph text:{1}",listItem,paraText);
}
}问候,
Celeste
Hello together,
I have a rather tricky problem. I need to find the enumeration symbol in front of a paragraph, like
1) This is the first line
2) this is the second line
In this case the 1) and 2) is not contained within the paragraph itself, but hidden somewhere else.
Is there any way to get this information?
Kind regards,
Simon
Hi,
I suggest you use Open Xml PowerTools to quick retrieve the list paragraphs.
You could get it from NuGet.
For more information about Open Xml PowerTools, please visit https://github.com/OfficeDev/Open-Xml-PowerTools
Screen-Cast: WordprocessingML Numbering from Eric White's blog demonstrates how to use ListItemRetriever.
For more information about numbered list, please visit Working with Numbered Lists in Open XML WordprocessingML
E.g.
using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using System.Xml.Linq; using OpenXmlPowerTools; using (WordprocessingDocument doc = WordprocessingDocument.Open(fileName, false)) { MainDocumentPart mdp = doc.MainDocumentPart; XDocument xDoc = mdp.GetXDocument(); var paras = xDoc.Descendants(W.p); foreach (var para in paras) { string listItem = ListItemRetriever.RetrieveListItem(doc, para, null); string paraText = para.Descendants(W.t).Select(t => (string)t).StringConcatenate(); Console.WriteLine("List Item: {0} Paragraph text: {1}", listItem, paraText); } }Regards,
Celeste
这篇关于查找段落的枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!