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.

Thu Nov 24, 2022 9:39 am

Hello,
Im converting excel file into pdf using spire.office-7.11.2. My issue is Im trying to use 50MB size of file in conversion. But the API throws java.lang.OutOfMemoryError: Java heap space

Sample program is attached for your reference. I could not attach the sample source file due to file size limitation. Sample file can be downloaded from https://www.sampledocs.in/DownloadFiles/SampleFile?filename=sampledocs-50mb-xlsx-file&ext=xlsx

I really appreciate your help on this.

JavaHeapSpaceIssue.zip
(688 Bytes) Downloaded 174 times

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Fri Nov 25, 2022 3:57 am

Hello,

Thanks for your inquiry.
I reproduced your issue and logged it into our bug tracking system with the ticket number SPIREXLS-4314. Our development team will investigate and fix it. Once it is solved, I will inform you in time. Sorry for the convenience caused.

Sincerely
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 66
Joined: Mon Nov 07, 2022 8:10 am

Fri Nov 25, 2022 5:17 am

Hi Doris,
Thank you for the consideration. I will wait for the solution.

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Fri Nov 25, 2022 5:51 am

Hi,

Thanks for your feedback.
You are welcome. Once there is any update, I will inform you asap.

Sincerely
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 66
Joined: Mon Nov 07, 2022 8:10 am

Tue Nov 29, 2022 6:43 am

Hi,

Thanks for your patient waiting.
After further investigation, we found that the OutOfMemory error is related to JVM heap memory allocation, your input Excel has 50MB, it needs enough memory. Please change your code as below and increase the JVM to -Xms2048m -Xmx4096m. I have confirmed it can work well without OutOfMemory exception on my side. If you have any issue, just feel free to contact us.

Code: Select all
Workbook workbook = new Workbook();
workbook.loadFromFile(path);
workbook.getConverterSetting().setSheetFitToWidth(true);

for (int i=0;i < workbook.getWorksheets().size();i++){
    Worksheet worksheet = workbook.getWorksheets().get(i);

    for (int col = worksheet.getFirstColumn();col<=worksheet.getLastColumn();col++){
        CellStyle style = worksheet.getColumns()[col-1].getCellStyle();
        style.setShrinkToFit(true);
        style.setWrapText(false);
    }
    PageSetup pageSetup = worksheet.getPageSetup();
    pageSetup.setPrintArea(null);
}

workbook.saveToFile(outputFileName, FileFormat.PDF);
workbook.dispose();
System.out.println("processed excel file - "+file.getName());


Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 66
Joined: Mon Nov 07, 2022 8:10 am

Tue Nov 29, 2022 8:11 am

Hello Doris,

Yes, you saved my time. The given code works perfect.

Thanks much for your support

UshaThavasiappan
 
Posts: 109
Joined: Sat Oct 08, 2022 9:23 am

Tue Nov 29, 2022 8:49 am

Hello,

Glad to hear that, if there is anything else we can do for you in the future, just feel free to contact us!

Sincerely,
Doris
E-iceblue support team
User avatar

Doris.Liu
 
Posts: 66
Joined: Mon Nov 07, 2022 8:10 am

Return to Spire.XLS