gpt4 book ai didi

ms-word - 打开XML : Word - Getting all Paragraphs marked as “Heading1” style

转载 作者:行者123 更新时间:2023-12-04 17:24:37 26 4
gpt4 key购买 nike

我使用Word创建了一个带有标准normal.dot的Docx作为测试。 Hello世界级别的复杂性。

我希望获得all the paragraphs,这些单词在Word中用“Heading1style设置样式。

我可以获取所有段落,但不知道如何过滤到Heading1。

using (var doc = WordprocessingDocument.Open(documentFileName, false))
{
paragraphs = doc.MainDocumentPart.Document.Body
.OfType<Paragraph>().ToList();
}

最佳答案

    [Test]
public void FindHeadingParagraphs()
{

var paragraphs = new List<Paragraph>();

// Open the file read-only since we don't need to change it.
using (var wordprocessingDocument = WordprocessingDocument.Open(documentFileName, false))
{
paragraphs = wordprocessingDocument.MainDocumentPart.Document.Body
.OfType<Paragraph>()
.Where(p => p.ParagraphProperties != null &&
p.ParagraphProperties.ParagraphStyleId != null &&
p.ParagraphProperties.ParagraphStyleId.Val.Value.Contains("Heading1")).ToList();
}
}

关于ms-word - 打开XML : Word - Getting all Paragraphs marked as “Heading1” style,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11941332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com