Check a checkbox in workbook using Aspose.Cells for Java

Hi,


I have an existing excel template, which contains few check boxes.
I need to check those check boxes using aspose cells.

Is there a way to do it?


Thank you
Soniya.R



Hi Soniya,


Thank you for contacting Aspose support.

Yes, it is possible to mark the CheckBox as checked while using the CheckBox.CheckedValue property as demonstrated below. Please note, the code marks one CheckBox as checked. If you have more than one CheckBoxes in your worksheet, you can iterate over the collection and perform the same operation on all CheckBoxes.

Java

Workbook book = new Workbook(dir + “checkbox.xlsx”);
book.getWorksheets().get(0).getCheckBoxes().get(0).setCheckedValue(CheckValueType.CHECKED);
book.save(dir + “output.xlsx”);
Thanks Babar,

but it does not work. the check box is as it is.

I am using aspose 8.4 jar



Hi,


Please try our latest version/fix: Aspose.Cells for Java v8.8.2.2 (attached).

If you still find the issue with v8.8.2.2, provide us your template Excel file, we will check it soon.

Thank you.

Hi,


I tried the latest version. still it does not help
this is my sample java code

Workbook workbook=new Workbook(“C:/Users/soniya.r/Desktop/load/test.XLSX”);
Worksheet sheet = workbook.getWorksheets().get(0);
CheckBoxCollection checkBoxcoll = sheet.getCheckBoxes();
for (int i = 0; i < checkBoxcoll.getCount(); i++) {
sheet.getCheckBoxes().get(i).setCheckedValue(CheckValueType.CHECKED);
}
workbook.save(“C:/Users/soniya.r/Desktop/load/test.XLSX”);

sample excel template has two row, three col and two check boxes.

Thank you,

soniya.R

Hi Soniya,


Please share the source spreadsheet so we could test the scenario against it.
Hi,

Please find the attachment of the template


Thank you,
Soniya.R

Hi Soniya,


Thank you for sharing the sample spreadsheet. Upon reviewing it, I have noticed that the check-boxes in your sample are actually ActiveX controls rather than Form controls. Aspose.Cells APIs do not provide support for adding or manipulating the ActiveX controls at the moment. Moreover, same is the reason, the provided code snippet does not make any change to the controls in your sample.

We are sorry for the inconvenience caused.

Hi Babar,


Thank you for your instant help. I try with form controls


Thanks and Regards
Soniya.R

Hi Babar,


I tried with form control check box. with the same file. still it don’t work.

Is there any other way to solve this problem?

Thank you,
Soniya.R

Hi,


Please provide us your template Excel file containing form controls (including checkbox), we will check it soon.

Thank you.

Hi,


Please find the file


Hi,


Thanks for providing us template file.


Please try our latest version/fix: Aspose.Cells for Java (Latest Version)

I have tested your scenario/ case using the following sample code with your template file using v8.8.2.2, it works fine and please find attached the output Excel file for your reference. You will see both checkboxes are checked fine.
e.g
Sample code:

Workbook workbook = new Workbook(“test.xlsx”);
Worksheet worksheet = workbook.getWorksheets().get(0);
CheckBoxCollection cbc = worksheet.getCheckBoxes();
//Set all checkboxes checked.
for( int i = 0; i<cbc.getCount(); i++)
{
CheckBox cb = cbc.get(i);
cb.setValue(true);
cb.setCheckedValue(CheckValueType.CHECKED);

}
workbook.save(“out1.xlsx”);


Thank you.


Thank you amjad. It works fine

Thanks
Soniya.R

Hi,


Good to know that it is working fine on your side now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.