ASF Bugzilla – Attachment 23317 Details for
Bug 46774
Extreme memory usage in XSSF workbook
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Sample code that illustrates the bug
LightStressTest.java (text/plain), 5.98 KB, created by
Rob W
on 2009-02-26 15:08:56 UTC
(
hide
)
Description:
Sample code that illustrates the bug
Filename:
MIME Type:
Creator:
Rob W
Created:
2009-02-26 15:08:56 UTC
Size:
5.98 KB
patch
obsolete
>/* ==================================================================== > 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 com.kinesis.test; > >import org.apache.poi.xssf.usermodel.*; >import org.apache.poi.ss.util.CellRangeAddress; >import org.apache.poi.ss.usermodel.*; >import org.apache.poi.hssf.usermodel.HSSFWorkbook; > >import java.util.Map; >import java.util.HashMap; >import java.io.FileOutputStream; > >/** > * A small workout for Apache POI. Usage: LightStressTest -xls|xlsx > * > * @author Yegor Kozlov > */ >public class LightStressTest >{ > private static final String[] titles = { "Person", "ID", "Mon", "Tue", "Wed", > "Thu", "Fri", "Sat", "Sun", "Total\nHrs", "Overtime\nHrs", "Regular\nHrs" }; > > private static Object[][] sample_data = { > { "Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0 }, > { "Gisella Bronzetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0 }, }; > > public static void main(String[] args) throws Exception > { > Workbook wb; > Boolean biff8 = false; > > if (biff8) > wb = new HSSFWorkbook(); > else > wb = new XSSFWorkbook(); > > Map<String, CellStyle> styles = createStyles(wb); > > Sheet sheet = wb.createSheet("Test 1"); > PrintSetup printSetup = sheet.getPrintSetup(); > printSetup.setLandscape(true); > sheet.setFitToPage(true); > sheet.setHorizontallyCenter(true); > > // title row > Row titleRow = sheet.createRow(0); > titleRow.setHeightInPoints(45); > Cell titleCell = titleRow.createCell(0); > titleCell.setCellValue("Test title"); > titleCell.setCellStyle(styles.get("title")); > sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$L$1")); > > // header row > Row headerRow = sheet.createRow(1); > headerRow.setHeightInPoints(40); > Cell headerCell; > for (int i = 0; i < titles.length; i++) > { > headerCell = headerRow.createCell(i); > headerCell.setCellValue(titles[i]); > headerCell.setCellStyle(styles.get("header")); > } > > int rownum = 2; > int numrows = 10000; > int numcols = 255; //(biff8 ? 255 : 1500); > > for (int i = 0; i < numrows; i++) > { > Row row = sheet.createRow(rownum++); > if (i % 1000 == 0) System.out.println("processing row "+i); > for (int j = 0; j < numcols; j++) > { > Cell cell = row.createCell(j); > > //cell.setCellStyle(styles.get("cell")); > cell.setCellValue(i*j); > } > } > System.out.println("processed "+numrows+" rows"); > > // finally set column widths, the width is measured in units of 1/256th of a > // character width > System.out.print("setting widths ... "); > sheet.setColumnWidth(0, 30 * 256); // 30 characters wide > for (int i = 2; i < numcols; i++) > { > sheet.setColumnWidth(i, 6 * 256); // 6 characters wide > } > System.out.println("done"); > > // Write the output to a file > String file = "/Users/rob/stressTest1.xls"; > if (wb instanceof XSSFWorkbook) file += "x"; > > System.out.print("saving to file "+file+" ... "); > FileOutputStream out = new FileOutputStream(file); > wb.write(out); > out.close(); > System.out.println("done"); > > System.out.println("Finished."); > } > > /** > * Create a library of cell styles > */ > private static Map<String, CellStyle> createStyles(Workbook wb) > { > Map<String, CellStyle> styles = new HashMap<String, CellStyle>(); > CellStyle style; > Font titleFont = wb.createFont(); > titleFont.setFontHeightInPoints((short) 18); > titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD); > style = wb.createCellStyle(); > style.setAlignment(CellStyle.ALIGN_CENTER); > style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); > style.setFont(titleFont); > styles.put("title", style); > > Font monthFont = wb.createFont(); > monthFont.setFontHeightInPoints((short) 11); > monthFont.setColor(IndexedColors.WHITE.getIndex()); > style = wb.createCellStyle(); > style.setAlignment(CellStyle.ALIGN_CENTER); > style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); > style.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); > style.setFillPattern(CellStyle.SOLID_FOREGROUND); > style.setFont(monthFont); > style.setWrapText(true); > styles.put("header", style); > > style = wb.createCellStyle(); > style.setAlignment(CellStyle.ALIGN_CENTER); > style.setWrapText(true); > style.setBorderRight(CellStyle.BORDER_THIN); > style.setRightBorderColor(IndexedColors.BLACK.getIndex()); > style.setBorderLeft(CellStyle.BORDER_THIN); > style.setLeftBorderColor(IndexedColors.BLACK.getIndex()); > style.setBorderTop(CellStyle.BORDER_THIN); > style.setTopBorderColor(IndexedColors.BLACK.getIndex()); > style.setBorderBottom(CellStyle.BORDER_THIN); > style.setBottomBorderColor(IndexedColors.BLACK.getIndex()); > styles.put("cell", style); > > style = wb.createCellStyle(); > style.setAlignment(CellStyle.ALIGN_CENTER); > style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); > style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); > style.setFillPattern(CellStyle.SOLID_FOREGROUND); > style.setDataFormat(wb.createDataFormat().getFormat("0.00")); > styles.put("formula", style); > > style = wb.createCellStyle(); > style.setAlignment(CellStyle.ALIGN_CENTER); > style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); > style.setFillForegroundColor(IndexedColors.GREY_40_PERCENT.getIndex()); > style.setFillPattern(CellStyle.SOLID_FOREGROUND); > style.setDataFormat(wb.createDataFormat().getFormat("0.00")); > styles.put("formula_2", style); > > return styles; > } >}
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 46774
: 23317