aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-07-31 21:20:33 +0000
committerPJ Fanning <fanningpj@apache.org>2021-07-31 21:20:33 +0000
commitcceb9102549f645c8622371804e659de40fa69f2 (patch)
tree709172d21ffce535f6ab2b0e6b22c5ec26cb718e
parentf4cf7dc99e38e1faf4f6af960daf281fccf65b35 (diff)
downloadpoi-cceb9102549f645c8622371804e659de40fa69f2.tar.gz
poi-cceb9102549f645c8622371804e659de40fa69f2.zip
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
-rw-r--r--poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java7
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFSheet.java11
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/RowGeneratorFunction.java4
3 files changed, 21 insertions, 1 deletions
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java b/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java
index 9c53c4ee0b..0e13a4dce3 100644
--- a/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java
+++ b/poi-examples/src/main/java/org/apache/poi/examples/xssf/streaming/DeferredGeneration.java
@@ -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);
}
});
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFSheet.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFSheet.java
index 5687ef90de..42e7d2aca2 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFSheet.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/DeferredSXSSFSheet.java
@@ -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;
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/RowGeneratorFunction.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/RowGeneratorFunction.java
index b3d9511372..eb6f70fc27 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/RowGeneratorFunction.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/RowGeneratorFunction.java
@@ -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