我需要获取已为其分配标签值(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] 删除。
我来说两句