Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Dec 27, 2022 10:59 am

Good morning.
I'm using the library to convert an excel to a png image. The code that i'm using is this:

Code: Select all
com.spire.xls.Workbook w = new com.spire.xls.Workbook();
w.loadFromFile(pathname);
w.getConverterSetting().setSheetFitToPage(true);
w.getConverterSetting().setSheetFitToWidth(true);
w.getConverterSetting().setClearCacheOnConverted(true);
w.getConverterSetting().setYDpi(1200);
w.getConverterSetting().setXDpi(1200);

Worksheet worksheet = w.getWorksheets().get(0);

worksheet.saveToImage(png_pathname);


The result image is totally inaccurate as it can be see in the attached image. The text is not aligned well.
How can I resolve this problem?
Attachments
Immagine 2022-12-20 121316.png
example
Immagine 2022-12-20 121316.png (8.98 KiB) Viewed 1979 times

L43985it
 
Posts: 4
Joined: Mon Sep 05, 2022 1:18 pm

Wed Dec 28, 2022 6:48 am

Hi,

Thanks for your inquiry.
I simulated an Excel file to test your code with the latest version of Spire.Xls 12.11.8 for Java, but I did not reproduce your issue, you can see my output image.
output.png
output.png (25.59 KiB) Viewed 1953 times

Are you using the latest version of Spire.Xls for Java? If not, you can download it from our website (https://www.e-iceblue.com/Download/xls-for-java.html) and do some tests, if your issue still exists, please provide us with the following messages to help us work out a solution for you, you can send them to us via email (support@e-iceblue.com) or attach them here. Thanks for your assistance in advance.
1) the version of Spire.Xls in your project.
2) your input files.
3) your JDK version.
4) your test environment, such as OS info (E.g., Windows 10 64 bit) and region setting (E.g., China, Chinese).

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon Jan 09, 2023 6:22 am

Hi,

Greetings from E-iceblue.
How is your issue now? if it has not been solved, could you please provide us with the following messages to help us work out a solution for you? Thanks for your assistance.
1) the version of Spire.Xls in your project.
2) your input files.
3) your JDK version.
4) your test environment, such as OS info (E.g., Windows 10 64 bit) and region setting (E.g., China, Chinese).

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon Jan 16, 2023 4:01 pm

Hi,
I haven't solved the issue. I'm using Open JDK 11.0.16.1 on Red Hat Enterprise Linux Server v7.9 x64.
Is maybe there an incompatibility with Open JDK?
Best regards.

L43985it
 
Posts: 4
Joined: Mon Sep 05, 2022 1:18 pm

Tue Jan 17, 2023 10:59 am

Hi,

Thanks for your feedback.
I did a test with Open JDK 11 and centos 7.9 (we don’t have the OS you mentioned), but I still did not reproduce your issue, I guess this was caused by the lacking of some fonts, the server does not install the fonts that your test files need, you can install them in your server or upload them to the server and set the font path in your java code. You can see the following code for reference.
Code: Select all
        String pathname = "sample.xlsx";
        String png_pathname = "sample.png";
        com.spire.xls.Workbook w = new com.spire.xls.Workbook();
        w.loadFromFile(pathname);
        // relative path
        String[] font = {"font"};
        w.setCustomFontFilePaths(font);
        w.getConverterSetting().setSheetFitToPage(true);
        w.getConverterSetting().setSheetFitToWidth(true);
        w.getConverterSetting().setClearCacheOnConverted(true);
        w.getConverterSetting().setYDpi(1200);
        w.getConverterSetting().setXDpi(1200);
        Worksheet worksheet = w.getWorksheets().get(0);
        worksheet.saveToImage(png_pathname);


if your issue still exists after the test, you can contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Tue Jan 17, 2023 8:34 pm

Hi,
I've tried your proposed solution but it seems that doesn't work.
I've used this line of code to convert the font in the xlsx file:
Code: Select all
sheet.getCellRange(row, coln).getCellStyle().getExcelFont().setFontName("Nimbus Roman");

I've choosen "Nimbus Roman" as font because it is installed on the Linux server.
Do you have any other suggestions?
Best regards.

L43985it
 
Posts: 4
Joined: Mon Sep 05, 2022 1:18 pm

Wed Jan 18, 2023 11:13 am

Hi

Thanks for your feedback.
I need to ask you some questions to help us do a further investigation for you.
1) did you change font’s permissions to allow the read-write access? If not, you can try to change it?
2) did the phenomenon occur in other OS?
In addition, you can try the second solution I provided. If the issue still exists, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.XLS