【发布时间】:2020-12-30 13:15:34
【问题描述】:
我需要从 C# 中的 word 文档中提取带有项目符号样式的文本。我正在使用 aspose.words 库,但也欢迎使用不同库的解决方案。我已经可以上传文档并使用 header1 样式提取文本。但是当我尝试对项目符号样式进行相同操作时,我什么也得不到。
我正在使用下面的代码来获取带有 Heading1 样式的文本,并且可以正常工作。
var heading1 = doc
.GetChildNodes(NodeType.Paragraph, true)
.Cast<Aspose.Words.Paragraph>()
.ToArray()
.Where(p => p.ParagraphFormat.StyleIdentifier == StyleIdentifier.Heading1);
foreach (var head1 in heading1)
{
listBox11.Items.Add(head1.gettext()tostring());
}
我正在尝试使用下面的代码来获取带有项目符号样式的文本,但这不起作用。
var bullets = doc
.GetChildNodes(NodeType.Paragraph, true)
.Cast<Aspose.Words.Paragraph>()
.ToArray()
.Where(p => p.ParagraphFormat.StyleIdentifier == StyleIdentifier.ListBullet);
foreach (var bullet in bullets)
{
listBox19.Items.Add(bullet.GetText().ToString());
}
listBox19.Items.Add(bullet1.GetText().ToString());
我也尝试使用 listbullet1、2、3、4 和 5 样式标识符,但这也不能解决问题。
【问题讨论】:
-
基于对apireference.aspose.com/words/net/aspose.words/styleidentifier 的快速浏览,项目符号列表似乎有不止一种样式。尝试将第二个 Where() 子句更改为使用 StyleIdentifier.ListBullet2 等。也许问题在于使用的项目符号样式不是 ListBullet。
-
哦,对不起,我忘了提到我确实尝试了 listbullet1,2,3,4 和 5,但这也不能解决问题
标签: c# aspose.words .doc