wordpress hit counter
Re: How to insert a table inside a content control. - .Net - Development Tools - OpenXML Developer

Re: How to insert a table inside a content control.

Development Tools

Discussions about working with Open XML using a wide range of development tools

How to insert a table inside a content control.

  • rated by 0 users
  • This post has 1 Reply |
  • 1 Follower
  • Hi All,

     I am trying to append the a table inside a content control.

    For this first i created a table and when i am trying to append.

     DocumentFormat.OpenXml.Packaging.MainDocumentPart mainPart= file.MainDocumentPart;

    SdtBlock cc = mainPart.Document.Body.Descendants().Where(r => r.SdtProperties.GetFirstChild().Val == "TagName").Single();

     -- Create table logic

    -- Table name is theTable

    cc.Append(theTable)

     please let me know where i am going wrong.

    The word generate agfter saving the file is not opening.

     

    Regards

    Nishant Sharma

  • Hi Nishant,

    The table needs to be a child of the w:sdtContent element, not a child of the SdtProperties. Following is valid markup for a spreadsheet within a content control:

      <w:body>
        <w:sdt>
          <w:sdtPr>
            <w:id w:val="1801180825"/>
            <w:placeholder>
              <w:docPart w:val="DefaultPlaceholder_1082065158"/>
            </w:placeholder>
          </w:sdtPr>
          <w:sdtContent>
            <w:tbl>
              <w:tr>
                <w:tc>
                  <w:tcPr>
                    <w:tcW w:w="4788"
                           w:type="dxa"/>
                  </w:tcPr>
                  <w:p>
                    <w:r>
                      <w:t>a</w:t>
                    </w:r>
                  </w:p>
                </w:tc>
                <w:tc>
                  <w:tcPr>
                    <w:tcW w:w="4788"
                           w:type="dxa"/>
                  </w:tcPr>
                  <w:p>
                    <w:r>
                      <w:t>b</w:t>
                    </w:r>
                  </w:p>
                </w:tc>
              </w:tr>
              <w:tr>
                <w:tc>
                  <w:tcPr>
                    <w:tcW w:w="4788"
                           w:type="dxa"/>
                  </w:tcPr>
                  <w:p>
                    <w:r>
                      <w:t>c</w:t>
                    </w:r>
                  </w:p>
                </w:tc>
                <w:tc>
                  <w:tcPr>
                    <w:tcW w:w="4788"
                           w:type="dxa"/>
                  </w:tcPr>
                  <w:p>
                    <w:r>
                      <w:t>d</w:t>
                    </w:r>
                  </w:p>
                </w:tc>
              </w:tr>
            </w:tbl>
            <w:p/>
          </w:sdtContent>
        </w:sdt>
      </w:body>
    

Page 1 of 1 (2 items)