我如何使用open xml从word文档中获取<w:pict>标签

时间:2015-07-01 10:09:21

标签: c# linq openxml-sdk

我有一个文档,其中包含表中的一些<w:pict>标记。 我如何使用openxml或XDocument读取/获取它 我想删除然后在文档中添加更新的<w:pict>标记

 <w:tr w:rsidR="007F23F0" w:rsidTr="00773840">
    <w:tc>
      <w:tcPr>
        <w:tcW w:w="4395" w:type="dxa" />
      </w:tcPr>
      <w:p w:rsidR="007F23F0" w:rsidP="00855D6B" w:rsidRDefault="007F23F0">
        <w:r>
          <w:t>Approver Signature:</w:t>
        </w:r>
        <w:fldSimple w:instr=" DOCPROPERTY  A1_Sign  \* MERGEFORMAT ">
          <w:r w:rsidR="00773840">
            <w:t>A1_Sign</w:t>
          </w:r>
        </w:fldSimple>
        <w:r w:rsidR="00773840">
          <w:pict>
            <v:shape id="_x0000_i1026" style="width:127.5pt;height:47.25pt" filled="t" o:preferrelative="f" type="#_x0000_t75" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml">
              <v:imagedata r:id="rId7" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" />
              <o:lock v:ext="edit" aspectratio="f" />
            </v:shape>
          </w:pict>
        </w:r>
      </w:p>
      <w:p w:rsidR="007F23F0" w:rsidP="00855D6B" w:rsidRDefault="007F23F0" />
      <w:p w:rsidR="007F23F0" w:rsidP="00855D6B" w:rsidRDefault="007F23F0" />
    </w:tc>
  </w:tr>

1 个答案:

答案 0 :(得分:0)

            using (WordprocessingDocument document = WordprocessingDocument.Open(fileName, false))
            {                    
                var run = document.MainDocumentPart.Document.Descendants<Run>().ToList();
                foreach (var eachrun in run)
                {              
                        var pic = eachrun.Descendants<Picture>().ToList();
                        foreach (var eachshape in pic)
                        {
                           --your code---
                        }                       
                }
            }