如何从Word XML中的w:sdtContent获取段落样式

大斯拉

我需要获取已为其分配标签值(COntentControl)的段落的样式。现在我在单词的段落中添加了contentControl(即)标记值,我可以获取我为其分配了标记值的相应段落的文本,

case "DocumentFormat.OpenXml.Wordprocessing.SdtBlock":
    SdtBlock p1 = (SdtBlock)DocElement;
    string content1 = p1.InnerText;

    if (!string.IsNullOrEmpty(content1))
        dt.Rows.Add(content1);
    break;

并将该参数添加到表中,但是当我将word文档保存为XML格式时,我需要获取参数的样式,然后获取这些代码

    <w:sdtContent>
        <w:p w:rsidR="00D57D79" w:rsidRDefault="00176023">
            <w:pPr>
                <w:pStyle w:val="Heading1"/>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman"/>
                    <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                    <w:lang w:val="en-US"/>
                </w:rPr>
            </w:pPr>
            <w:r>
                <w:rPr>
                    <w:rFonts w:eastAsia="Times New Roman"/>
                    <w:shd w:val="clear" w:color="auto" w:fill="auto"/>
                    <w:lang w:val="en-US"/>
                </w:rPr>
                <w:t>Use Case Model</w:t>
            </w:r>
        </w:p>
    </w:sdtContent>
</w:sdt>

我需要获取该段落的相应样式。如何获取这些样式?

大斯拉
 case "DocumentFormat.OpenXml.Wordprocessing.SdtBlock":
                        SdtBlock p1 = (SdtBlock)DocElement;
                        content1 = p1.InnerText;

                        IEnumerable<Paragraph> pp = p1.Descendants<Paragraph>();
                        foreach (Paragraph para in pp)
                        {
                         style=   GetParagraphStyleId(para);
                        }

其中GetParagraphStyleId(para)具有

 public string GetParagraphStyleId(Paragraph p)
    {
        string ParaStyleIdValue = string.Empty;
        if (p.ParagraphProperties != null)
        {
            if (p.ParagraphProperties.ParagraphStyleId != null)
            {
                if (p.ParagraphProperties.ParagraphStyleId.Val != null)
                {
                    ParaStyleIdValue = p.ParagraphProperties.ParagraphStyleId.Val.Value;
                }
            }
        }
        return ParaStyleIdValue;
    }

  Using this i get the Style of the paragraph from sdtContent.           

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从 Word 插件中的 Word 文档中获取段落编号?

如何在MS Word的单个段落中使用多种样式

如何从Microsoft Word样式中删除“ + not at”?

如何在VSTO的页眉中获取每个段落的Word.Range.Start / End

如何使用 OpenXml.Wordprocessing 和 C# 在 MS Word 中创建自定义样式链接(段落和字符)

Word中的简单段落文本使用哪种样式?

在 VBA for Word 中从多个样式段落的开头删除字符

如何从桌面Word中的JavaScript插件处理选定的段落?

如何在 Word 2010 中对齐段落以填充整行

如何使用 Interop.Word 反转段落

如何在段落样式中保留覆盖字符样式 - Ms Word?

c#如何在Word中获取标准字体样式对象

如何使用python docx获取Word文档中的实际文本样式

Word 样式如何应用其格式设置?

如何在Word文档样式中更改字体颜色

如何仅在Word中以特定样式查找和替换?

如何以编程方式在ms word中设置文本样式?

如何在默认居中的Word中设置标题样式?

如何获取样式表中定义的名称空间前缀,而不是从输入XML中获取

如何获取 Microsoft Word 文档的 HTML 内容?

如何从gensim获取word2index

通过Word API获取当前段落的样式/字体(字体大小,颜色等)

在Word文档中找不到段落和表格(开放XML)

MS Word 宏:如何用新段落替换重复的段落?

在Word中,如何反转表中的行?

如何使用JavaScript在段落中获取文本

如何在Applescript中的Word 2011中获取选定的文本

如何从c#中的word文件中获取注释的位置

如何摆脱Word中的项目符号模式