ASF Bugzilla – Attachment 37703 Details for
Bug 65077
Workbook.close() clears the second (the last) sheet data in previously saved file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
example source file
TestPoiStreaming.java (text/plain), 1.92 KB, created by
Andrey Grigoriev
on 2021-01-13 11:20:32 UTC
(
hide
)
Description:
example source file
Filename:
MIME Type:
Creator:
Andrey Grigoriev
Created:
2021-01-13 11:20:32 UTC
Size:
1.92 KB
patch
obsolete
>package com.company.excel; > >import org.apache.poi.ss.usermodel.*; >import org.apache.poi.xssf.streaming.SXSSFWorkbook; >import org.apache.poi.xssf.usermodel.XSSFWorkbook; > >import java.io.File; >import java.io.FileOutputStream; >import java.io.IOException; > >public class TestPoiStreaming { > public static void main(String[] args) throws IOException { > int rowNumber = 0; > int cellNumber = 0; > String outputFileName = "c:/temp/test1.xlsx"; > File outFile = new File(outputFileName); > File outFile2 = new File("c:/temp/test2.xlsx"); > Workbook workbook = new SXSSFWorkbook(100); > try { > Sheet sheet = workbook.createSheet("Sheet1"); > Row row = null; > for (int i = 0; i < 1000; i++) { > row = sheet.createRow(rowNumber++); > cellNumber = 0; > for (int j = 1; j <= 10; j++) { > Cell cell = row.createCell(cellNumber++); > cell.setCellValue(String.valueOf(j)); > } > } > try (FileOutputStream out = new FileOutputStream(outFile)) { > workbook.write(out); > } > } finally { > workbook.close(); > ((SXSSFWorkbook) workbook).dispose(); > } > > workbook = new SXSSFWorkbook((XSSFWorkbook) WorkbookFactory.create(outFile), 100); > try { > Sheet sheet = workbook.createSheet("Sheet2"); > Row row = null; > for (int i = 0; i < 1000; i++) { > row = sheet.createRow(rowNumber++); > cellNumber = 0; > for (int j = 1; j <= 10; j++) { > Cell cell = row.createCell(cellNumber++); > cell.setCellValue(String.valueOf(j)); > } > } > try (FileOutputStream out = new FileOutputStream(outFile2)) { > workbook.write(out); > } > } finally { > workbook.close(); > ((SXSSFWorkbook) workbook).dispose(); > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 65077
: 37703