Hi,
I have bumped into a small problem, that I can’t handle without your help. I have two tables (single row in both of them), and all I wan’t is to move these two tables to the newly created SDT control (just to wrap these two tables with SDT control).
I have attached input document that I am using in this example (table_in.docx) and also, output from my code (table_out.docx). As you can see, width and alignment in both of these tables is not accurate.
My goal, is to preserve these table settings.
I have tried to clone tables, and to delete originals, and also few variations of adding into a new SDT control, and nothing helped.
Additional info: the input document is just a simplified example of the real document. I could have many tables like these inside the document, and perhaps, some static text in between, or maybe another part of the document that I want to convert to another SDT. Some SDT will be inside another SDT, etc. So, if you include all of these facts, I believe that re-creating Document with the Document builder is not an option?
Code that creates SDT:
Document doc = new Document(@"d:\Projects\AsposeSandbox\word\table_in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
List nodes = doc.Sections[0].Body.GetChildNodes(NodeType.Table, false).ToArray().ToList();
StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.RichText, MarkupLevel.Block);
sdt.ChildNodes.Clear();
nodes.Last().ParentNode.InsertAfter(sdt, nodes.Last());
nodes.ForEach(x => sdt.AppendChild(x));
doc.Save(@"d:\Projects\AsposeSandbox\word" + "table_out.docx");
Thanks in advance,
Nikola