setColumnWidthPixel not working as expected

Hi,

I noticed that the function setColumnWidthPixel() sometimes doesn’t work correctly. This has something to do with with the Excel Default Font. If I run the following code:

 Workbook workbook = new Workbook();
 Worksheet worksheet = workbook.getWorksheets().get(0);
 Cell cell = worksheet.getCells().get(0, 0);
 Style style = workbook.getDefaultStyle();
 style.getFont().setName("Calibri");
 style.getFont().setSize(11);
 style.getFont().setBold(false);
 workbook.setDefaultStyle(style);
 worksheet.getCells().setColumnWidthPixel(cell.getColumn(),100);
 workbook.save("test.xlsx");

I’m using aspose-cells 18.1 (Java version) and if I ran this code on a Linux machine, the Width of the first Column is set to 87px instead of 100px.

Can you fix this bug?

Best regards,
Hugo Freixo

@Hugo_Freixo,

I simply tested your scenario/case by using your sample code on Windows env. and it works fine, the width of the first column in the output file (attached) is set to 100px. The Calibri font is installed on C:\Windows\Fonts folder as I checked. I guess the required font (“Calibri”) is not installed on your system. On Linux environment, Aspose.Cells does not use any specific fonts folder, so it is always better you should explicitly specify the fonts folder/directory in code (at the start). You may place all your required fonts (especially “Calibri” (.ttf file(s)) for your current case in some folder, e.g “/usr/Temp/Fonts” (please note, this is just an example, you can use any directory of your choice) and then run this code as following:
e.g
Sample code:

//Search fonts in this directory, true means also seach sub-folders
FontConfigs.setFontFolder("/usr/Temp/Fonts", true);

Workbook workbook = new Workbook();
............

Also, see the documents in the section for your reference:

Let us know if you still find the issue.
file1.zip (6.1 KB)

Hi Amjad,

That seemed to fix the problem, but an odd thing happened.
After installing the fonts, when I open the file (generated by the same code) I get the correct width. When my friend opens the same file on his machine the Width in Pixels is 125px. It’s exactly the same file, generated on a Linux machine. My Excel version is Microsoft Office Professional Plus 2016 version 16.0.4266.1001 64bit and my friend’s version is Microsoft Office Professional Plus 2016 version 16.0.4639.1000 64bit.

Why do you think this happens? Is there any fix I can add to my code to prevent this problem?

Best regards,
Hugo Freixo

@Hugo_Freixo,

That is strange. Do you mean the file is generated on your (Linux) machine (with all the required fonts installed and fonts folder is set in the code accordingly) using your sample code? Do you open the same generated file (on your system) on your friend’s computer? What is your friend computer environment (OS, etc.)? Are the required fonts installed on your friend’s system as well? Also provide us the generated Excel file and some screenshots to show the issue (when opening the file onto the system), we will check it soon.

@Hugo_Freixo,

Furthermore, if both you and your friend’s machine have installed the workbook’s default font, then
the difference may be caused by different display settings. e.g. one is 100%, the other is 125%
We suggest that both machines should set display setting to 100%, it should fix the issue.

Hi Amjad,

You are right. The Display settings were different and that was the problem.

Thank you very much for your help.

Best regards,
Hugo Freixo

@Hugo_Freixo,

Good to know that your issue is sorted out by using 100% display settings. 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.