1

I am using aspose-cells.jar for Excel export in my application. I am stuck where I need to dynamically create sheets in the template. My original Excel template contains 2 sheets.

  1. Sheet1 contains the table and pie-chart.
  2. Sheet2 contains the data for the table and pie-chart.

Depending upon the number of sample data selected these sheets has to be cloned i.e. Suppose two dates are selected then:

  • Sheet1 should contain the graph and pie-chart for first date.
  • Sheet2 should contain the graph and pie-chart for second date.

And

  • Sheet3 should contain the data for first date.
  • Sheet4 should contain the data for second date.
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Vipul Ranjan
  • 35
  • 1
  • 6

1 Answers1

0

You can use the Worksheets.addCopy method to clone an existing worksheet.

// Open the workbook
Workbook book = new Workbook(srcDoc);
boolean bSomeCondition = true;
// If some condition is true e.g. dates
if (bSomeCondition)
{
    // Copy first worksheet
    book.getWorksheets().addCopy("Sheet1");
    // Copy the second worksheet
    book.getWorksheets().addCopy("Sheet2");
}
// Save the workbook
book.save(dstDoc);
Saqib Razzaq
  • 1,408
  • 1
  • 10
  • 10