Browse Source

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
tags/REL_5_1_0
PJ Fanning 2 years ago
parent
commit
cceb910254

+ 7
- 0
poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java View File

@@ -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);
}
});

+ 11
- 0
poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFSheet.java View File

@@ -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;
}

+ 3
- 1
poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/RowGeneratorFunction.java View File

@@ -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…
Cancel
Save