Setting value on ActiveXControl in Excel worksheet causes "java.lang.NullPointerException" in Python

Hi,

We are using the Java API wrapped for Python. We create a workbook, write about 50 values to it, then save and close.

It has worked fine so far, but our activeX comboboxes do not update to reflect the newly written values. In an attempt to update the displayed values manually, we are accessing all activeX controls and setting their value to their linked cell value using setValue.

This seems to work, as they take on the new value quite happily. However, on attempting to save the workbook, a Null Pointer Exception is thrown on the Java side.

Any help would be appreciated.

Code sample:

shapes = ws.getShapes()
numShapes = shapes.getCount()
for i in range(numShapes):
shape = shapes.get(i)
if shape.activeXControl:
ctl=shape.activeXControl
refCellName = ctl.getLinkedCell().replace(’$’,’’)
refCellValue = ws.getCells().get(refCellName).getValue()
ctl.setValue(refCellValue)


Thanks,

Rian


Hi,

Thanks for your posting and using Aspose.Cells.

Please download and try the latest version: Aspose.Cells for Java v8.9.2.3 and see if it makes any difference and resolves your issue.

I have tested this issue with the latest version using the following Java sample code and it successfully sets the value of Combo Box ActiveX Control. I have attached the sample excel file used in this code and the output excel file generated by the code for your reference.

Please try the same code in Python with my provided sample excel file and see what results you get? Do you still get such an exception? Please make sure, you use the latest version to test this code.

Please note, it seems, you are not type casting Shape ActiveX Control to Combo Box ActiveX Control. There is no setValue() method for ActiveX Control but for Combo Box ActiveX Control, setValue() method exists. This is the reason, you are getting null pointer exception.

If your issue still occurs, then please provide us your sample excel file, we will look into it and help you asap.

Java

Workbook wb = new Workbook(dirPath + “sample.xlsx”);

Worksheet ws = wb.getWorksheets().get(0);

Shape shp = ws.getShapes().get(0);

ComboBoxActiveXControl c = (ComboBoxActiveXControl)shp.getActiveXControl();

c.setValue(“This is modified data.”);

wb.save(dirPath + “output.xlsx”);