简体   繁体   English

使用Java中的Aspose单元动态创建工作表?

[英]Dynamic sheet creation using Aspose cells in Java?

I am using aspose-cells.jar for Excel export in my application. 我在应用程序中使用aspose-cells.jar进行Excel导出。 I am stuck where I need to dynamically create sheets in the template. 我被困在需要在模板中动态创建图纸的位置。 My original Excel template contains 2 sheets. 我原来的Excel模板包含2张纸。

  1. Sheet1 contains the table and pie-chart. Sheet1包含表格和饼图。
  2. Sheet2 contains the data for the table and pie-chart. Sheet2包含表和饼图的数据。

Depending upon the number of sample data selected these sheets has to be cloned ie Suppose two dates are selected then: 根据所选样本数据的数量,必须克隆这些工作表,即假设选择了两个日期,然后:

  • Sheet1 should contain the graph and pie-chart for first date. Sheet1应该包含图表和饼图的第一个日期。
  • Sheet2 should contain the graph and pie-chart for second date. Sheet2应该包含第二个日期的图形和饼图。

And

  • Sheet3 should contain the data for first date. Sheet3应包含第一个日期的数据。
  • Sheet4 should contain the data for second date. Sheet4应包含第二个日期的数据。

You can use the Worksheets.addCopy method to clone an existing worksheet. 您可以使用Worksheets.addCopy方法来克隆现有工作表。

// 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM