diff options
author | PJ Fanning <fanningpj@apache.org> | 2020-07-03 21:36:14 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2020-07-03 21:36:14 +0000 |
commit | 7166eb3496cec4585634033f79f1b4e95a391b64 (patch) | |
tree | 4998e521ad4955723709a20ebd17f91a722348c3 /src | |
parent | 3aa573bdd866a8f2ab814533a4d3623d2d4bd5ff (diff) | |
download | poi-7166eb3496cec4585634033f79f1b4e95a391b64.tar.gz poi-7166eb3496cec4585634033f79f1b4e95a391b64.zip |
add DeferredGeneration sample
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1879493 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/examples/src/org/apache/poi/xssf/streaming/examples/DeferredGeneration.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/examples/src/org/apache/poi/xssf/streaming/examples/DeferredGeneration.java b/src/examples/src/org/apache/poi/xssf/streaming/examples/DeferredGeneration.java new file mode 100644 index 0000000000..ce1db096ac --- /dev/null +++ b/src/examples/src/org/apache/poi/xssf/streaming/examples/DeferredGeneration.java @@ -0,0 +1,63 @@ +/* + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + +package org.apache.poi.xssf.streaming.examples; + +import org.apache.poi.xssf.streaming.DeferredSXSSFSheet; +import org.apache.poi.xssf.streaming.DeferredSXSSFWorkbook; +import org.apache.poi.xssf.streaming.SXSSFCell; +import org.apache.poi.xssf.streaming.SXSSFRow; + +import java.io.FileOutputStream; + +/** + * An example that outputs a simple generated workbook that uses deferred creation of the rows in the sheets. + * When the workbook is written to an output stream, the output data is streamed immediately. + * There is no collation of the data in temp files prior to writing the overall file. + * This depends on how efficient the row generating functions are. + */ +public final class DeferredGeneration { + + private DeferredGeneration() {} + + public static void main(String[] args) throws Exception { + String filename; + if(args.length == 0) { + filename = "deferred-generation.xlsx"; + } else { + filename = args[0]; + } + try (DeferredSXSSFWorkbook wb = new DeferredSXSSFWorkbook()){ + for(int i = 0; i < 10; i++) { + DeferredSXSSFSheet sheet = wb.createSheet("Sheet" + i); + sheet.setRowGenerator((sh) -> { + for (int r = 0; r < 1000; r++) { + SXSSFRow row = sheet.createRow(r); + for (int c = 0; c < 100; c++) { + SXSSFCell cell = row.createCell(c); + cell.setCellValue("abcd"); + } + } + }); + } + wb.write(new FileOutputStream(filename)); + System.out.println("wrote " + filename); + } + } +} |