Error in excel file generated through Aspose Cells


We are trying to generate an Excel through the following steps(Attached is the code used for file generation) :-
1.) An Excel file is saved in the system and is being used as the template for the final output.
2.)The template is being converted into a workbook using Aspose API.
3.)The workbook is then saved into an outputstream and then subsequently in a byte array format using Apose API.
4.)Using the Byte Array the Excel is being generated.


// TemplatePage.getString(“pyFileSource”) contains the base64EncodedString of the template which is then decoded to a byte array

byte[] tempBytes = new“pyFileSource”));

//reading the data from byte arrays(tempBytes) as streams tempIS = new;

//Creating the workbook
com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(tempIS);

//capturing the data written to a stream outStream = new;

//Saving the Workbook, com.aspose.cells.SaveFormat.
//Converting outStream to byteArray
byte[] xlBytes = outStream.toByteArray();

//Sending file to browser
String result=tools.sendFile(xlBytes,FileName,false,null,true);

}catch(Exception e){System.out.println(“Exception”+e);}

Error:- When the generated file is opened it through an error stating that Excel found unreadable content in Generated file.

Attached is the original Excel File that was being used as a template and will display no error while opening.
Along with that the generated file is also attached that displays the error on opening the file.

The version of Aspose Cells being used is

Please provide a resolution for the same.
Aspose Cells (1.7 MB)


Thanks for the template file and sample code segment.

Please try our latest version/fix: Aspose.Cells for Java v17.9.3

I have tested using the following sample code with v17.9.3, it works fine. The output XLSM file is opened fine into MS Excel:
Sample code:

import java.util.*;

import com.aspose.cells.*;
import com.aspose.cells.Workbook;
import com.aspose.cells.Worksheet;

public class ErrorInExcel1

    public static void main(String[] args) throws Exception

/* //This works fine.
Workbook workbook = new Workbook("OriginalFile (1).xlsm");"out1OriginalFile1.xlsm");

//This equally works fine.
byte[] data = FileUtils.readFileToByteArray(new File("f:\\files\\OriginalFile (1).xlsm"));
            ByteArrayInputStream inStream =  new ByteArrayInputStream(data);
            final Workbook doc = new Workbook(inStream);
            // Save the modified document into out stream
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
  , SaveFormat.XLSM);
            //You can then get the PDF document back into the InputStream as follows
            final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());

            // Use this to convert the stream to a .pdf file
            final OutputStream outputStream = new FileOutputStream("f:/files/out1.xlsm");
            IOUtils.copy(inputStream, outputStream);


Hope, this helps a bit.