From 63543343fb88508fa8abf1c4e3c93f9d5cab92e6 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Tue, 6 Nov 2007 18:54:50 +0000 Subject: [PATCH] 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 --- .../content/xdocs/hssf/quick-guide.xml | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) 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