mirror of https://github.com/apache/poi.git
update docs about deferred SXSSF and limitations on what can be done in row generating function
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891937 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f4cf7dc99e
commit
cceb910254
|
@ -18,6 +18,8 @@
|
|||
package org.apache.poi.examples.xssf.streaming;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xssf.streaming.DeferredSXSSFSheet;
|
||||
import org.apache.poi.xssf.streaming.DeferredSXSSFWorkbook;
|
||||
|
@ -36,10 +38,15 @@ public class DeferredGeneration {
|
|||
try (DeferredSXSSFWorkbook wb = new DeferredSXSSFWorkbook()) {
|
||||
DeferredSXSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||
|
||||
// cell styles should be created outside the row generator function
|
||||
CellStyle cellStyle = wb.createCellStyle();
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
|
||||
sheet1.setRowGenerator((ssxSheet) -> {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Row row = ssxSheet.createRow(i);
|
||||
Cell cell = row.createCell(1);
|
||||
cell.setCellStyle(cellStyle);
|
||||
cell.setCellValue("value " + i);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -41,11 +41,22 @@ public class DeferredSXSSFSheet extends SXSSFSheet {
|
|||
super(workbook, xSheet, workbook.getRandomAccessWindowSize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported in DeferredSXSSFSheet
|
||||
*
|
||||
* @throws RuntimeException this is unsupported
|
||||
*/
|
||||
@Override
|
||||
public InputStream getWorksheetXMLInputStream() throws IOException {
|
||||
throw new RuntimeException("Not supported by DeferredSXSSFSheet");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a function to generate rows for the sheet. This function should only create rows and cells.
|
||||
* Any other settings like creating cell styles should be done in separate calls outside this function.
|
||||
*
|
||||
* @param rowGenerator {@link RowGeneratorFunction}
|
||||
*/
|
||||
public void setRowGenerator(RowGeneratorFunction rowGenerator) {
|
||||
this.rowGenerator = rowGenerator;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,9 @@ import org.apache.poi.util.Beta;
|
|||
public interface RowGeneratorFunction {
|
||||
|
||||
/**
|
||||
* Generate and add rows to the sheet
|
||||
* Generate and add rows to the sheet. Note that anything that does not relate to creating rows and cells
|
||||
* should not be done inside this function. It is best to create cell styles and sheet level settings in
|
||||
* separate calls outside this function.
|
||||
*
|
||||
* @param sheet the sheet
|
||||
* @throws Exception the exception
|
||||
|
|
Loading…
Reference in New Issue