Word provides ability to create nested content controls. Is there a way to add a content control inside another content control using Spire.Doc?
I have tried the following to embed a Picture Content Control inside a Rich Text Control, but it doesn't seem to work.
- Code: Select all
Section stagingSection = doc.AddSection();
Paragraph stagingParagraph = stagingSection.AddParagraph();
stagingParagraph.AppendHTML(htmlContent);
StructureDocumentTag rtsdt = CreateDocumentControl(alias, tag, SdtType.RichText, LockSettingsType.UnLocked);
Section richTextControlSection = doc.AddSection();
richTextControlSection.Body.ChildObjects.Add(rtsdt);
StructureDocumentTag sdt = CreateDocumentControl(alias, tag, SdtType.Picture, LockSettingsType.SDTLocked);
Section pictureControlSection = doc.AddSection();
pictureControlSection.Body.ChildObjects.Add(sdt);
//DocPicture pic = new DocPicture(doc) { Width = 10, Height = 10 };
//DocPicture pic = paragraph.AppendPicture(htmlContent);
//pic.LoadImage(Image.FromFile("Logo.jpg"));
//pic.LoadImage(htmlContent);
foreach (DocumentObject obj in stagingSection.Body.ChildObjects)
{
//Clone the elements from section in sdt
sdt.SDTContent.ChildObjects.Add(obj.Clone());
}
//Remove the html section
doc.Sections.Remove(stagingSection);
foreach (DocumentObject obj in pictureControlSection.Body.ChildObjects)
{//obj is a StructureDocumentTag
//Clone the elements from section in sdt
rtsdt.SDTContent.ChildObjects.Add(obj.Clone());
}
doc.Sections.Remove(pictureControlSection);