We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Read Grouped Radio Button From Excel

Hi Aspose ,

I am currently trying to read Radio Buttons From Excel Files.
I am using following code to read name and value of radio button. This work’s if Excel has direct radio button objects.
Currently We are having a excel file where Radio buttons are grouped and We are unable to print it’s value. I have also written First if block to get Each shape from Group. But Type of this Group Object is coming as picture and Not as Radio Buttons So I am unable to fetch radio buttons value.
Please let me know if I am missing something here. I am attaching sample excel file here to test.
To simplify How to fetch Value of Radio Button From Attached Excel ? TestRadioButton.zip (33.0 KB)

ShapeCollection shapes = worksheet.getShapes();
for (Object object : shapes) {
if(object instanceof GroupShape ) {
GroupShape group = (GroupShape) object;
for(int shapeIndex = 0; shapeIndex < group.getGroupedShapes().length; shapeIndex++) {
Shape groupedShape = group.getGroupedShapes()[shapeIndex];
System.out.println(groupedShape.getName());

			}
		
		} else if(object instanceof RadioButton) {
			RadioButton button = (RadioButton) object;
			String name = button.getName();
			boolean checked = button.isChecked();
			System.out.println(" " + name  + " " + " : " + checked);
			
		}
	}

@ketaki2092,

Thanks for the template file and code segment.

Please try the following sample code, it works as expected:
e.g
Sample code:

.......
ShapeCollection shapes = worksheet.getShapes();
		for(int i = 0; i < shapes.getCount(); i++)
		{
		      Shape shape = (Shape)shapes.get(i);
		      
		      if (shape instanceof GroupShape)
		      {
		            GroupShape groupShape = (GroupShape)shape;
		            for(int g = 0; g < groupShape.getGroupedShapes().length; g++)
		            {
		                  Shape groupedShape = groupShape.getGroupedShapes()[g];
		                  System.out.println(groupedShape.getName() + " is grouped under " + groupShape.getName());
		            }
		      }
		      
		      else if (shape instanceof RadioButton) 
		      {
		            RadioButton radioButton = (RadioButton)shape;
		            System.out.println(radioButton.getName() + " " + radioButton.isChecked() + " " + radioButton.isGroup());
		      }
		      
		      else if (shape instanceof CheckBox)
		      {
		            CheckBox checkBox = (CheckBox)shape;
		            System.out.println(checkBox.getName() + " " + checkBox.getCheckedValue() + " " + checkBox.isGroup());
		      } 
		} 

Hope, this helps a bit.

Thank you for your response but from attached template I am getting radio buttons as pictures … DId you tries template shared by me ? It is not coming as instance of RadioButton but …it is groupshape and Picture of radio button in it. How to fetch value of Radio button attached in my template file ?

@ketaki2092,

After further evaluation, we found your radio buttons are actually ActiveX controls instead of form RadioButton controls. Please try the following sample code to accomplish your task:
e.g
Sample code:

........
ShapeCollection shapes = worksheet.getShapes();
		for(int i = 0; i < shapes.getCount(); i++)
		{
		      Shape shape = (Shape)shapes.get(i);
		      
		      if (shape instanceof GroupShape)
		      {
		            GroupShape groupShape = (GroupShape)shape;
		            for(int g = 0; g < groupShape.getGroupedShapes().length; g++)
		            {
		                  Shape groupedShape = groupShape.getGroupedShapes()[g];
		                  
		                  if (groupedShape.getActiveXControl()!= null)
		                  {
		                      ActiveXControl c = groupedShape.getActiveXControl();
		                      if (c.getType()== ControlType.RADIO_BUTTON)
		                      {
		                          RadioButtonActiveXControl radioButtonActiveX = (RadioButtonActiveXControl)c;
		                          System.out.println(groupedShape.getName() + " acticeX (radio button) is grouped under " + groupShape.getName() + ", the control is checked: " + radioButtonActiveX.getValue());
		                       		                          
		                      }
		                  }
		                  
		            }
		      }
		      
		      
		     
		} 

Hope, this helps a bit.