【问题标题】:How to get the Paragraph style from w:sdtContent in word XML如何从 word XML 中的 w:sdtContent 获取段落样式
【发布时间】:2014-06-09 14:03:20
【问题描述】:

我需要获取我分配了标签值的段落的样式( COntentControl )。 现在我已经在 word 中的段落中添加了 contentControl (ie) Tag 值,我可以获取我分配了标签值的相应段落的文本,

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

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

我正在将该 para 添加到表格中,但我需要获取 para 的样式,当我以 XML 格式保存 word 文档时,我得到了这些代码

    <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>

我需要获取那个段落对应的样式。如何获取那些样式?

【问题讨论】:

    标签: xml vba ms-word ms-office office-interop


    【解决方案1】:
     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.           
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多