I am working on a task related to reading an excel which contains radio buttons and checkbox using Java, I have tried a lot but can't move further on this, when I am trying to read the data of cell containing Checkbox it is returning a null value.
Can someone please help with this.
Controls are not contained in the cells but hovers in the drawing layer over the sheet as shapes and only are anchored to the cells. So the cell may be null (because of no content in it) although a shape hovers over it and is anchored to it.
Moreover there are two different kinds of controls possible. There are form controls and
ActiveX
controls. The states ofActiveX
controls are stored in binary code partsactiveX1.bin
and thus getting the state of them is very hard.In earlier
Excel
versions (2007 for example) the anchor informations of all controls are stored in/xl/drawings/vmlDrawing1.vml
only. Later versions are storing them in default drawing and withinparts in the sheet
XML
too. Fortunately there is also/xl/drawings/vmlDrawing1.vml
for backwards compatibility.The following code does parsing the
/xl/drawings/vmlDrawing1.vml
to get the control which is possible anchored to a cell. If found, it gets this control and if this control is a form control and not aActiveX
control, then it also can get it's state. ForActiveX
controls it gets only the information, that a "Pict" is anchored to this cell.Excel:
Code:
Result: