Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I have developed one console application by the help of Sharepoint client DLL and OpenXML.dll (2.5). In this application I am trying to first delete one table (Last table of the document) then pragmatically creating one table and adding this table at the end of the word document. But after completing the operation when I am opening the document in Open XML SDK 2.5 productivity tool it is showing the OpenXmlUnknownElement . below is the line
OpenXmlUnknownElement openXmlUnknownElement1 = OpenXmlUnknownElement.CreateOpenXmlUnknownElement("<w:tbl xmlns:w="\" http:="" schemas.openxmlformats.org="" wordprocessingml="" 2006="" main\""=""><w:tblpr><w:tblw w:w="\" 10030\""="" w:type="\" dxa\""=""><w:tblcellspacing w:w="\" 36\""="" w:type="\" dxa\""=""><w:tblind w:w="\" 435\""="" w:type="\" dxa\""=""><w:tbllayout w:type="\" fixed\""=""><w:tblcellmar><w:left w:w="\" 115\""="" w:type="\" dxa\""=""><w:right w:w="\" 115\""="" w:type="\" dxa\""=""><w:tbllook w:val="\" 01e0\""=""><w:tblgrid><w:gridcol w:w="\" 2186\""=""><w:gridcol w:w="\" 7844\""=""><w:tr w:rsidr="\" 000110da\""="" w:rsidtr="\" 00aa570b\""="" w14:paraid="\" 501bf0ef\""="" w14:textid="\" 77777777\""="" xmlns:w14="\" http:="" schemas.microsoft.com="" office="" word="" 2010="" wordml\""=""><w:trpr><w:tblcellspacing w:w="\" 36\""="" w:type="\" dxa\""=""><w:tc><w:tcpr><w:tcw w:w="\" 2078\""="" w:type="\" dxa\""=""><w:tcborders><w:top w:val="\" single\""="" w:color="\" c0c0c0\""="" w:sz="\" 2\""="" w:space="\" 0\""=""><w:left w:val="\" single\""="" w:color="\" c0c0c0\""="" w:sz="\" 2\""="" w:space="\" 0\""=""><w:bottom w:val="\" single\""="" w:color="\" c0c0c0\""="" w:sz="\" 2\""="" w:space="\" 0\""=""><w:right w:val="\" single\""="" w:color="\" c0c0c0\""="" w:sz="\" 2\""="" w:space="\" 0\""=""><w:shd w:val="\" clear\""="" w:color="\" auto\""="" w:fill="\"><w:valign w:val="\" center\""=""><w:p w:rsidrpr="\" 008e0e2e\""="" w:rsidr="\" 000110da\""="" w:rsidp="\" 00aa570b\""="" w:rsidrdefault="\" w14:paraid="\" 0356805a\""="" w14:textid="\" 77777777\""=""><w:ppr><w:jc w:val="\" right\""=""><w:rpr><w:b><w:r w:rsidrpr="\" 008e0e2e\""=""><w:rpr><w:b><w:t>Employee Comments:<w:bookmarkstart w:name="\" _goback\""="" w:displacedbycustomxml="\" next\""="" w:id="\" 0\""=""><w:bookmarkend w:displacedbycustomxml="\" next\""="" w:id="\" 0\""=""><w:sdt><w:sdtpr><w:text w:multiline="\" true\""=""><w:sdtcontent><w:tc><w:tcpr><w:tcw w:w="\" 7736\""="" w:type="\" dxa\""=""><w:tcborders><w:top w:val="\" single\""="" w:color="\" c0c0c0\""="" w:sz="\" 2\""="" w:space="\" 0\""=""><w:left w:val="\" single\""="" w:color="\" c0c0c0\""="" w:sz="\" 2\""="" w:space="\" 0\""=""><w:bottom w:val="\" single\""="" w:color="\" c0c0c0\""="" w:sz="\" 2\""="" w:space="\" 0\""=""><w:right w:val="\" single\""="" w:color="\" c0c0c0\""="" w:sz="\" 2\""="" w:space="\" 0\""=""><w:shd w:val="\" clear\""="" w:color="\" auto\""="" w:fill="\" eaf1dd\""=""><w:valign w:val="\" center\""=""><w:p w:rsidr="\" 000110da\""="" w:rsidp="\" 00ee0340\""="" w:rsidrdefault="\" 00ce7b7b\""="" w14:paraid="\" 2886a2b0\""="" w14:textid="\" 0aa781c0\""=""><w:r><w:t>Test by nabhendu<w:r><w:br><w:permend w:id="\" 1680364608\""="">");
I have attached the my code block also.

Body bd = doc.MainDocumentPart.Document.Body;
DocumentFormat.OpenXml.Wordprocessing.Table table = doc.MainDocumentPart.Document.Body.Elements<documentformat.openxml.wordprocessing.table>().Last();
table.RemoveAllChildren();

doc.MainDocumentPart.Document.Body.Elements<documentformat.openxml.wordprocessing.table>().Last().Append(CreateEmployeeCommentMetaTag(table));

Paragraph paragraph51 = new Paragraph() { RsidParagraphAddition = "00C207B3", RsidParagraphProperties = "00C207B3", RsidRunAdditionDefault = "00C207B3", ParagraphId = "103C3DDD", TextId = "77777777" };

ParagraphProperties paragraphProperties41 = new ParagraphProperties();
ParagraphStyleId paragraphStyleId10 = new ParagraphStyleId() { Val = "Heading3" };
SpacingBetweenLines spacingBetweenLines3 = new SpacingBetweenLines() { Before = "0" };

ParagraphMarkRunProperties paragraphMarkRunProperties37 = new ParagraphMarkRunProperties();
FontSize fontSize62 = new FontSize() { Val = "24" };
FontSizeComplexScript fontSizeComplexScript70 = new FontSizeComplexScript() { Val = "22" };

paragraphMarkRunProperties37.Append(fontSize62);
paragraphMarkRunProperties37.Append(fontSizeComplexScript70);

paragraphProperties41.Append(paragraphStyleId10);
paragraphProperties41.Append(spacingBetweenLines3);
paragraphProperties41.Append(paragraphMarkRunProperties37);

paragraph51.Append(paragraphProperties41);

Paragraph paragraph52 = new Paragraph() { RsidParagraphMarkRevision = "00C207B3", RsidParagraphAddition = "00DA659F", RsidParagraphProperties = "00C207B3", RsidRunAdditionDefault = "00E1588B", ParagraphId = "103C3DDE", TextId = "77777777" };

ParagraphProperties paragraphProperties42 = new ParagraphProperties();
ParagraphStyleId paragraphStyleId11 = new ParagraphStyleId() { Val = "Heading3" };
SpacingBetweenLines spacingBetweenLines4 = new SpacingBetweenLines() { Before = "0" };

ParagraphMarkRunProperties paragraphMarkRunProperties38 = new ParagraphMarkRunProperties();
FontSize fontSize63 = new FontSize() { Val = "24" };
FontSizeComplexScript fontSizeComplexScript71 = new FontSizeComplexScript() { Val = "20" };

paragraphMarkRunProperties38.Append(fontSize63);
paragraphMarkRunProperties38.Append(fontSizeComplexScript71);

paragraphProperties42.Append(paragraphStyleId11);
paragraphProperties42.Append(spacingBetweenLines4);
paragraphProperties42.Append(paragraphMarkRunProperties38);

Run run120 = new Run() { RsidRunProperties = "00C207B3" };

RunProperties runProperties87 = new RunProperties();
FontSize fontSize64 = new FontSize() { Val = "24" };
FontSizeComplexScript fontSizeComplexScript72 = new FontSizeComplexScript() { Val = "20" };

runProperties87.Append(fontSize64);
runProperties87.Append(fontSizeComplexScript72);
Text text118 = new Text();
text118.Text = "Additional Comments (optional)";

run120.Append(runProperties87);
run120.Append(text118);

Run run121 = new Run() { RsidRunProperties = "00C207B3", RsidRunAddition = "00DA659F" };

RunProperties runProperties88 = new RunProperties();
FontSize fontSize65 = new FontSize() { Val = "24" };
FontSizeComplexScript fontSizeComplexScript73 = new FontSizeComplexScript() { Val = "20" };

runProperties88.Append(fontSize65);
runProperties88.Append(fontSizeComplexScript73);
Text text119 = new Text();
text119.Text = ":";

run121.Append(runProperties88);
run121.Append(text119);

paragraph52.Append(paragraphProperties42);
paragraph52.Append(run120);
paragraph52.Append(run121);

Paragraph paragraph53 = new Paragraph() { RsidParagraphAddition = "00F17E7E", RsidParagraphProperties = "00DA659F", RsidRunAdditionDefault = "00F17E7E", ParagraphId = "170A3E91", TextId = "14C679B7" };
BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", Id = "0" };
BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { Id = "0" };

paragraph53.Append(bookmarkStart1);
paragraph53.Append(bookmarkEnd1);
Table table7 = new Table();

TableProperties tableProperties7 = new TableProperties();
TableStyle tableStyle2 = new TableStyle() { Val = "TableGrid" };
TablePositionProperties tablePositionProperties2 = new TablePositionProperties() { LeftFromText = 180, RightFromText = 180, VerticalAnchor = VerticalAnchorValues.Text, HorizontalAnchor = HorizontalAnchorValues.Margin, TablePositionY = 214 };
TableWidth tableWidth7 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto };
Shading shading21 = new Shading() { Val = ShadingPatternValues.Solid, Color = "auto", Fill = "8DB3E2", ThemeFill = ThemeColorValues.Text2, ThemeFillTint = "66" };
TableLayout tableLayout6 = new TableLayout() { Type = TableLayoutValues.Fixed };
TableLook tableLook7 = new TableLook() { Val = "04A0" };

tableProperties7.Append(tableStyle2);
tableProperties7.Append(tablePositionProperties2);
tableProperties7.Append(tableWidth7);
tableProperties7.Append(shading21);
tableProperties7.Append(tableLayout6);
tableProperties7.Append(tableLook7);

TableGrid tableGrid7 = new TableGrid();
GridColumn gridColumn14 = new GridColumn() { Width = "10296" };

tableGrid7.Append(gridColumn14);

TableRow tableRow9 = new TableRow() { RsidTableRowMarkRevision = "0063050C", RsidTableRowAddition = "00F17E7E", RsidTableRowProperties = "00315155", ParagraphId = "3788A34B", TextId = "77777777" };

TableCell tableCell19 = new TableCell();

TableCellProperties tableCellProperties19 = new TableCellProperties();
TableCellWidth tableCellWidth19 = new TableCellWidth() { Width = "10296", Type = TableWidthUnitValues.Dxa };
Shading shading22 = new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = "8DB3E2", ThemeFill = ThemeColorValues.Text2, ThemeFillTint = "66" };

tableCellProperties19.Append(tableCellWidth19);
tableCellProperties19.Append(shading22);

Paragraph paragraph54 = new Paragraph() { RsidParagraphMarkRevision = "0063050C", RsidParagraphAddition = "00F17E7E", RsidParagraphProperties = "00F17E7E", RsidRunAdditionDefault = "00F17E7E", ParagraphId = "555BA2FD", TextId = "4BAB9469" };

ParagraphProperties paragraphProperties43 = new ParagraphProperties();

ParagraphMarkRunProperties paragraphMarkRunProperties39 = new ParagraphMarkRunProperties();
Bold bold83 = new Bold();
BoldComplexScript boldComplexScript78 = new BoldComplexScript();
FontSize fontSize66 = new FontSize() { Val = "22" };
FontSizeComplexScript fontSizeComplexScript74 = new FontSizeComplexScript() { Val = "20" };

paragraphMarkRunProperties39.Append(bold83);
paragraphMarkRunProperties39.Append(boldComplexScript78);
paragraphMarkRunProperties39.Append(fontSize66);
paragraphMarkRunProperties39.Append(fontSizeComplexScript74);

paragraphProperties43.Append(paragraphMarkRunProperties39);

Run run122 = new Run() { RsidRunProperties = "008E0E2E" };

RunProperties runProperties89 = new RunProperties();
Bold bold84 = new Bold();

runProperties89.Append(bold84);
Text text120 = new Text();
text120.Text = "Employee Comments:";

run122.Append(runProperties89);
run122.Append(text120);

Run run123 = new Run();

RunProperties runProperties90 = new RunProperties();
Bold bold85 = new Bold();

runProperties90.Append(bold85);
Text text121 = new Text() { Space = SpaceProcessingModeValues.Preserve };
text121.Text = " ";

run123.Append(runProperties90);
run123.Append(text121);

Run run124 = new Run();

RunProperties runProperties91 = new RunProperties();
Color color3 = new Color() { Val = "808080", ThemeColor = ThemeColorValues.Background1, ThemeShade = "80" };

runProperties91.Append(color3);
Text text122 = new Text() { Space = SpaceProcessingModeValues.Preserve };
text122.Text = " ";

run124.Append(runProperties91);
run124.Append(text122);

Run run125 = new Run();
Text text123 = new Text() { Space = SpaceProcessingModeValues.Preserve };
text123.Text = " ";

run125.Append(text123);

SdtRun sdtRun3 = new SdtRun();

SdtProperties sdtProperties7 = new SdtProperties();
SdtAlias sdtAlias6 = new SdtAlias() { Val = "EmployeeComments" };
Tag tag6 = new Tag() { Val = "EmployeeComments" };
SdtId sdtId7 = new SdtId() { Val = 1825780944 };
Lock lock7 = new Lock() { Val = LockingValues.SdtContentLocked };
ShowingPlaceholder showingPlaceholder3 = new ShowingPlaceholder();
//DataBinding dataBinding7 = new DataBinding() { PrefixMappings = "xmlns:ns0=\'http://schemas.microsoft.com/office/2006/metadata/properties\' xmlns:ns1=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:ns2=\'$ListId:BackupDocuments;\' xmlns:ns3=\'3938b449-2e68-4216-9dc4-c08645db9ef5\' xmlns:ns4=\'5372fb52-7a60-4bd4-a3af-476b3cc6b985\' xmlns:ns5=\'682afeaa-49b3-4d3c-a7fe-099dfe46c58d\' xmlns:ns6=\'12e95924-d241-4538-b351-919a55fa0c8a\' ", XPath = "/ns0:properties[1]/documentManagement[1]/ns5:EmployeeComments[1]", StoreItemId = "{3353F0FD-49CA-4627-9B69-CF6589E6B26C}" };
DataBinding dataBinding7 = new DataBinding() { PrefixMappings = "xmlns:ns0=\'http://schemas.microsoft.com/office/2006/metadata/properties\' xmlns:ns1=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:ns2=\'$ListId:BackupDocuments;\' xmlns:ns3=\'3938b449-2e68-4216-9dc4-c08645db9ef5\' xmlns:ns4=\'5372fb52-7a60-4bd4-a3af-476b3cc6b985\' xmlns:ns5=\'682afeaa-49b3-4d3c-a7fe-099dfe46c58d\' xmlns:ns6=\'12e95924-d241-4538-b351-919a55fa0c8a\' ", XPath = "/ns0:properties[1]/documentManagement[1]/ns6:EmployeeComments[1]", StoreItemId = "{3353F0FD-49CA-4627-9B69-CF6589E6B26C}" };
SdtContentText sdtContentText7 = new SdtContentText() { MultiLine = true };

sdtProperties7.Append(sdtAlias6);
sdtProperties7.Append(tag6);
sdtProperties7.Append(sdtId7);
sdtProperties7.Append(lock7);
sdtProperties7.Append(showingPlaceholder3);
sdtProperties7.Append(dataBinding7);
sdtProperties7.Append(sdtContentText7);
SdtEndCharProperties sdtEndCharProperties7 = new SdtEndCharProperties();

SdtContentRun sdtContentRun3 = new SdtContentRun();

Run run126 = new Run() { RsidRunProperties = "00E1233A", RsidRunAddition = "003A1325" };

RunProperties runProperties92 = new RunProperties();
RunStyle runStyle4 = new RunStyle() { Val = "PlaceholderText" };

runProperties92.Append(runStyle4);
Text text124 = new Text();
text124.Text = "[Automatically populated]";

run126.Append(runProperties92);
run126.Append(text124);

sdtContentRun3.Append(run126);

sdtRun3.Append(sdtProperties7);
sdtRun3.Append(sdtEndCharProperties7);
sdtRun3.Append(sdtContentRun3);

paragraph54.Append(paragraphProperties43);
paragraph54.Append(run122);
paragraph54.Append(run123);
paragraph54.Append(run124);
paragraph54.Append(run125);
paragraph54.Append(sdtRun3);

tableCell19.Append(tableCellProperties19);
tableCell19.Append(paragraph54);

tableRow9.Append(tableCell19);

table7.Append(tableProperties7);
table7.Append(tableGrid7);
table7.Append(tableRow9);

return table7;

Can anyone please help me for resolving this issue?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900