Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Jun 08, 2022 8:56 pm

I have seen examples of creating word content controls. I want to insert Html content inside word content control. but I dont see any Api in spire Doc. that converts the html to wml that can be inserted inside the content controls. Can you point me to the right direction.

Below is the code iam trying

Code: Select all
        private static void ExecuteSpire()
        {
            Document document = new Document();
            Section section = document.AddSection();
            Paragraph paragraph = section.AddParagraph();

            StructureDocumentTagInline sd = new StructureDocumentTagInline(document);
            paragraph.ChildObjects.Add(sd);
            TextRange rt = new TextRange(document);

            //Document document1 = new Document();
            //Section sec = document1.AddSection();
            //sec.AddParagraph().AppendHTML("<h1> this is Document </h1>");

            sd = new StructureDocumentTagInline(document);
            paragraph.ChildObjects.Add(sd);
            sd.SDTProperties.SDTType = SdtType.RichText;
            SdtText text = new SdtText(true);
            text.IsMultiline = true;
            sd.SDTProperties.ControlProperties = text;
            sd.SDTProperties.LockSettings = LockSettingsType.SDTLocked;
            rt = new TextRange(document);
            rt.Text = "<html><h1>this is Document </h1></html>";
            sd.SDTContent.ChildObjects.Add(rt);

            string resultfile = "sample.docx";
            document.SaveToFile(resultfile, FileFormat.Docx);
            System.Diagnostics.Process.Start(resultfile);
        }

varunreddyparam
 
Posts: 1
Joined: Sun Jan 16, 2022 5:39 pm

Thu Jun 09, 2022 8:39 am

Hi,

Thank you for your inquiry.
Kindly note the Word content control does not provide an interface to insert HTML directly, but you can refer to my code below to achieve your requirement. Please feel free to contact me if you have any questions.
Code: Select all
            //Create document instance
            Document doc = new Document();
            //Add a section to append html
            Section section = doc.AddSection();
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendHTML("<html><h1>this is Document </h1></html>");

            //Create StructureDocumentTag
            StructureDocumentTag sdt = new StructureDocumentTag(doc);
            //Create a section to add sdt
            Section section2 = doc.AddSection();
            section2.Body.ChildObjects.Add(sdt);

            //Specify the SDT type
            sdt.SDTProperties.SDTType = SdtType.RichText;
            sdt.SDTProperties.LockSettings = LockSettingsType.SDTLocked;
            foreach (DocumentObject obj in section.Body.ChildObjects)
            {
                //Clone the elements from section in sdt
                sdt.SDTContent.ChildObjects.Add(obj.Clone());
            }
            //Remove the html section
            doc.Sections.Remove(section);
            //Save document
            doc.SaveToFile("sample.docx", FileFormat.Docx);


Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Mon Aug 22, 2022 7:47 am

Hi,

Greetings from E-iceblue.
Has your problem been effectively solved now? Can you give us some feedback at your convenience?

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.Doc

cron