From: Yegor Kozlov Date: Tue, 6 Nov 2007 18:54:50 +0000 (+0000) Subject: added a note to re-use fonts instead of creating a font for each cell X-Git-Tag: REL_3_0_2_BETA1~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=63543343fb88508fa8abf1c4e3c93f9d5cab92e6;p=poi.git added a note to re-use fonts instead of creating a font for each cell git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@592521 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/hssf/quick-guide.xml b/src/documentation/content/xdocs/hssf/quick-guide.xml index e40dc0dcb3..6dc4dc909b 100644 --- a/src/documentation/content/xdocs/hssf/quick-guide.xml +++ b/src/documentation/content/xdocs/hssf/quick-guide.xml @@ -330,7 +330,40 @@ FileOutputStream fileOut = new FileOutputStream("workbook.xls"); wb.write(fileOut); fileOut.close(); - + +

+ Note, the maximum number of unique fonts in a workbook is limited to 32767 ( + the maximum positive short). You should re-use fonts in your apllications instead of + creating a font for each cell. +Examples: +

+

Wrong:

+ + for (int i = 0; i < 10000; i++) { + HSSFRow row = sheet.createRow(i); + HSSFCell cell = row.createCell((short) 0); + + HSSFCellStyle style = workbook.createCellStyle(); + HSSFFont font = workbook.createFont(); + font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + style.setFont(font); + cell.setCellStyle(style); + } + +

Correct:

+ + + HSSFCellStyle style = workbook.createCellStyle(); + HSSFFont font = workbook.createFont(); + font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + style.setFont(font); + for (int i = 0; i < 10000; i++) { + HSSFRow row = sheet.createRow(i); + HSSFCell cell = row.createCell((short) 0); + cell.setCellStyle(style); + } + +
Custom colors