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

Free Support Forum - aspose.com

Wierd behaviour when using Worksheet.autoFitColumns() throws java.awt.HeadlessException


When I was working with Aspose cells 7.0.0, I came across a weird behavior when I use Worksheet.autoFitColumns() which throws java.awt.HeadlessException

"Exception in thread “main” java.awt.HeadlessException
at sun.awt.HeadlessToolkit.getScreenResolution(HeadlessToolkit.java:189)"
But, this happens only when I create multiple workbook in the same JVM context and if the “java.awt.headless” system property is set to “true”. otherwise this issue doesn’t occur.

when “java.awt.headless” is set to true
If Worksheet.autoFitColumns() is used and when one workbook is created, it works fine
If Worksheet.autoFitColumns() is used and when multiple workbook is created, it fails

In either of the other case [set java.awt.headless - false or comment Worksheet.autoFitColumns()], creating multiple workbook works properly.

System.setProperty(“java.awt.headless”, “true”);

int MAX_BOOKS = 2;

for (int i = 0; i < MAX_BOOKS; i++) {
System.out.println("Creating workbook " + (i + 1));

Workbook workbook = new Workbook();
Worksheet dataSheet = workbook.getWorksheets().add(“Data”);
Cells cells = dataSheet.getCells();

cells.get(“A1”).setValue(“Column 1”);
cells.get(“B1”).setValue(“Column 2”);
cells.get(“A2”).setValue(“Column 3”);


workbook.save(“Test” + i + “.xls”);

System.out.println(“workbook " + (i + 1) + " Created”);

I have attached the java code along with this.

Is this a known issue? What alternate can be used for this issue to get resolved, when java.awt.headless is set to true.

Aspose OEM License Holder


Thanks for the sample project.

I can find the issue using your sample code as you mentioned. Setting “java.awt.headless” to false works fine with auto-fitting columns operation as you pointed out. We need to investigate the issue. I have logged the issue with an id: CELLSJAVA-30489. We will look into it soon.

Thank you.

The issues you have found earlier (filed as 30489) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Thanks for the fix.,