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.

Thu Dec 22, 2016 10:49 am

Hello,

to get the content of a MS Word formfield by it’s name I can use the following code:

WordApp = CreateObject("Word.Application")
WordApp.Documents.Open("sample.docx")
sContent = WordApp.ActiveDocument.SelectContentControlsByTitle("myName").Item(1).Range.Text

Is there an equivalent of the SelectContentControlsByTitle-method in Spire.doc? I haven’t found it.

Thank you.

Best Reagards
Christoph

EmbacherChristoph
 
Posts: 3
Joined: Sun Dec 18, 2016 10:35 am

Fri Dec 23, 2016 2:15 am

Dear Christoph,

Thanks for your inquiry.
Here is sample code for your reference.
Code: Select all
            Document doc = new Document(@"F:\testing\doc form\original document\9418UserForm.doc");
            foreach (Section sec in doc.Sections)
            {
                foreach (FormField field in sec.Body.FormFields)
                {
                    if (field.Name == "email")
                    {
                      string text = field.Text;
                    }
                }
            }

And here is a tutorial maybe help you.
https://www.e-iceblue.com/Tutorials/Spi ... -in-C.html
If there still is issue, please provide us your sample file, and then we will provide you corresponding code.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Dec 23, 2016 2:19 pm

Dear Betsy,

many thanks! I tried your code but it seems, that none of the formfields in the Doc (textbox, combobox, checkbox) will be found. Attached you will find my sample file. It would be nice if you could help me to find the error.

Best regards
Christoph

EmbacherChristoph
 
Posts: 3
Joined: Sun Dec 18, 2016 10:35 am

Mon Dec 26, 2016 2:44 am

Dear Christoph,

Thanks for your information.
Please reference following code.
Code: Select all
            Document doc = new Document(@"F:\testing\doc form\original document\9418Sample.docx");
            foreach (Section section in doc.Sections)
            {
                foreach (Body body in section.ChildObjects)
                {
                    foreach (DocumentObject bodyObj in body.ChildObjects)
                    {
                        if (bodyObj is StructureDocumentTag)
                        {
                            IStructureDocument sdt = bodyObj as IStructureDocument;
                            //get the text in textbox
                            if (sdt.SDTProperties.Tag == "TextBox")
                            {
                                foreach (DocumentObject SObj in sdt.ChildObjects)
                                {
                                    if (SObj is Paragraph)
                                    {
                                        Paragraph par = SObj as Paragraph;
                                        string text = par.Text;
                                    }
                                }
                            }
                            //get all value in combobox
                            if (sdt.SDTProperties.Tag == "Combobox")
                            {
                                SdtComboBox cb = sdt.SDTProperties.ControlProperties as SdtComboBox;
                                foreach (SdtListItem item in cb.ListItems)
                                {
                                    string value = item.Value;
                                }
                            }
                        }
                    }
                }
            }
            //I found in the last paragraph, you first insert text "Checkbox" and then insert content control.
            foreach (DocumentObject Pobj in doc.LastParagraph.ChildObjects)
            {
                if (Pobj is TextRange)
                {
 
                }
                if (Pobj is StructureDocumentTagInline)
                {

                }
            }
        }

If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Dec 27, 2016 6:22 am

Dear Christoph,

Did you test the code ? Did it hlep you solve the issue ?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Tue Dec 27, 2016 6:36 pm

Dear Betsy,

thanks a lot, it works fine.

Best regards
Christoph

EmbacherChristoph
 
Posts: 3
Joined: Sun Dec 18, 2016 10:35 am

Wed Dec 28, 2016 1:17 am

Dear Christoph,

Thanks for your feedback.
Please feel free to contact us if there is any question. We will be happy to help you.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc