Question: Need sample code for generating excel template-based output using Aspose.Cells Java

Hi Aspose Team,

We are using the jars below to generate excel output using Aspose-cells.18.5, we have a requirement to generate ExcelTemplate based output where input as XML or PDF file.
<aspose-cells.version>18.5</aspose-cells.version>
<aspose-words.version>16.6.0</aspose-words.version>
<aspose-pdf.version>16.11.0</aspose-pdf.version>

Can I please get an example of generating ExcelTemplate based output using Aspose cells in Java? sample output below for reference.

image.png (36.8 KB)

Please let me if you need any inputs.

Thanks
Durga

@nishitha,

Thanks for your query and screenshot.

You can import XML data using Workbook.importXml method if it suits your needs. Aspose.Cells supports to import from variety of data sources, so you may also try to save your xml data to some arrays or list, etc. using your own code and then import into Excel worksheet using Aspose.Cells APIs.

Moreover, if your input file is PDF, then you may try to use Aspose.PDF for Java to open the file and then save it as Excel file, see the document for your reference:
https://docs.aspose.com/display/pdfjava/Convert+PDF+to+Excel+XLS+and+XLSX

Hope, this helps a bit.

Hi Aspose Team,

Thank you for your help, We had tried with below code

private void processExcel() {
String input = “E:\sample\9149.pdf”;
InputStream is = null;
try {
File licFile = new File(“E:\sample\GenerateExcel\src\Aspose_Total.lic”);
is = new FileInputStream(licFile);
License lic = new License();
lic.setLicense(is);
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
} finally {
try {
if (is != null)
is.close();
} catch (Exception ignored) {

                }
            }
            
    try
    {
        Document pdfDocument = new Document(input);          
        ExcelSaveOptions excelsave = new ExcelSaveOptions();          
        pdfDocument.save("E:\\sample\\test123.xls", excelsave);          
       
        
         Document doc = new Document(input);        
         ExcelSaveOptions options1 = new ExcelSaveOptions();         
         options1.setFormat(ExcelSaveOptions.ExcelFormat.XLSX);         
         doc.save("E:\\sample\\test1.xlsx", options1);
         
         
         System.out.println("end");
         } catch (Exception e) {
                System.out.println(e.toString());
                e.printStackTrace();
            }
    }

XLS format output was generated(attached generated output test123.xls) but it is like excel file not template format, we need excel output with given template format (like excel_template.xls attached)

and we are getting below error while executing the above code to generate xlsx format file. We are using aspose.pdf-18.6-java.jar

Exception in thread “main” java.lang.NoSuchMethodError: com.aspose.pdf.ExcelSaveOptions.setFormat(I)V
at com.javacodegeeks.example.HelloWorldApplication.processExcel(HelloWorldApplication.java:79)
at com.javacodegeeks.example.HelloWorldApplication.main(HelloWorldApplication.java:30)

Can you please provide sample code for generating an excel template file with input as a pdf or XML
Files.zip (107.8 KB)
file.

Thanks,
Durga

@nishitha,

Thanks for the code segment and details.

Since you are using Aspose.PDF for Java, so kindly post your issue with sample code, details and template files in Aspose.PDF forum, one of our colleagues from Aspose.PDF team will help you soon there.

Hi Team,

Please look into the request and provide us your valuable suggestions to achieve our requirement. Appriciate your help.

let me know if you need any clarifications.

Thanks
Durga

@nishitha,

I have created a new thread in Aspose.PDF forums to move your issue there. See your thread and follow up: