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>