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.

Sun May 03, 2015 4:01 am

Hi,

I'm trying to investigate getting and setting the value of checkbox content controls in Word Documents.

Getting the Content Control as per the earlier forum posts get a basic object but this seems to have no correspondence to the actual checkbox control.

Is there any way of getting/setting a Checkbox content control easily?

ascsoftware
 
Posts: 7
Joined: Mon Feb 10, 2014 6:48 pm

Mon May 04, 2015 3:40 am

Hello,

Thanks for your inquiry.
Please refer to the following code:
Code: Select all
 Document document = new Document();
            document.LoadFromFile(@"checkbox.docx");
            foreach (Section section in document.Sections)
            {
              foreach (FormField field in document.Sections[0].Body.FormFields)
                {
                    if (field.Type == FieldType.FieldFormCheckBox)
                    {
                        CheckBoxFormField checkBox = field as CheckBoxFormField;
                        checkBox.Checked = true;
                    }
                }
            }
            document.SaveToFile("output.docx", FileFormat.Docx);

If there are any questions, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon May 04, 2015 3:54 am

Hi Betsy,

Doesn't the code sample provided just apply to Form Fields?

I need to use the newer Content Controls introduced in Word 2010.

Kind Regards,

Courtney

ascsoftware
 
Posts: 7
Joined: Mon Feb 10, 2014 6:48 pm

Mon May 04, 2015 6:42 am

Hello,

Sorry that at present the Spire.Doc doesn't support the newer content controls.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon May 04, 2015 1:25 pm

Hi Betsy,

Thanks for your reply. In the end we built our own library in .NET to allow for these changes.

Kind Regards,

Courtney

ascsoftware
 
Posts: 7
Joined: Mon Feb 10, 2014 6:48 pm

Tue May 05, 2015 1:13 am

Hello,

Please feel free to contact us if you have some questions or needs.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed May 08, 2019 11:12 am

Hi,

I have checkbox's in the word template with bookmarks set as shown in the attached image. I need to identify the checkbox based on the bookmark and set the value of the checkbox as checked in the template and later save the template. We are using Spire.Doc and are able to replace other bookmark contents, challenge is only with Checkbox content
Note: there are multiple checkboxes and some might have to be checked and some not.

Please help!!!

rameshbabu6060@gmail.com
 
Posts: 1
Joined: Tue May 07, 2019 4:42 am

Thu May 09, 2019 11:46 am

Hi,

Thanks for your inquiry.
Our Spire.Doc can find the CheckBox according to the bookmark. But during testing, I found the status of CheckBox failed to be changed. Below is my testing code. I will submitted the issue to our Dev team for further investigating and fixing. If there is any update, we will let you know. Sorry for the inconvenience caused. In addition, could you please provide your input Word file, so that we can better fix your issue according to your actual case. You could send it to us via email. Thanks in advance.
Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"Sample.docx");
            BookmarksNavigator navigator = new BookmarksNavigator(doc);
            navigator.MoveToBookmark("bookmark");
            TextBodyPart textBodyPart = navigator.GetBookmarkContent();
            foreach (var item in textBodyPart.BodyItems)
            {
                if (item is Paragraph)
                {
                    foreach (var childObject in (item as Paragraph).ChildObjects)
                    {
                        if (childObject is StructureDocumentTagInline)
                        {
                            StructureDocumentTagInline st = childObject as StructureDocumentTagInline;
                            if (st.SDTProperties.SDTType == SdtType.CheckBox)
                            {
                                SdtCheckBox checkbox = st.SDTProperties.ControlProperties as SdtCheckBox;
                                checkbox.Checked = true;
                            }
                        }
                    }
                }
            }
           doc.SaveToFile("result.docx", FileFormat.Docx);

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Tue Nov 12, 2019 11:44 am

Hello!
I had the same problem than rameshbabu6060@gmail.com.
I can put the bookmark join to the checkbox control, but later, it is not posible from code, get the name of the control. It is not public property.
How can i get the name of the checkbox control?

checkbox.png



Other option it is used active control check box, but I haven't any sample in spire demo samples.
Do you have any sample to use check box active x control:

activexcheckbox.png

Thank you very much!

LauraNM
 
Posts: 77
Joined: Tue Feb 19, 2019 1:23 pm

Wed Nov 13, 2019 9:16 am

Hi,

Thanks for your inquiry.
I tested your case with Spire.Doc Pack(hot fix) Version:7.11.1, and the property checkboxField.Name is public, so I could get the name of the checkbox control. Below is my code for your reference.

Code: Select all
            Document doc = new Document();
            doc.LoadFromFile(@"……\filename.docx");
            foreach (Field f in doc.Fields)
            {
                switch (f.Type)
                {
                    case FieldType.FieldFormCheckBox:
                        CheckBoxFormField checkboxField = f as CheckBoxFormField;
                        Console.WriteLine(checkboxField.Name);
                        break;
                }
            }
            Console.Read();


Sorry that Spire.Doc doesn't support to create ActiveX Controls at present. We will consider adding this new feature into our upgrade schedule. Once there is any progress, we will inform you. Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Fri Nov 15, 2019 1:48 pm

Yes. It is!

Thank you very much!

LauraNM
 
Posts: 77
Joined: Tue Feb 19, 2019 1:23 pm

Mon Nov 18, 2019 1:17 am

Hi,

Thanks for your feedback.
Any question, welcome to contact us. Have a nice day.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.Doc