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
This commit is contained in:
Yegor Kozlov 2007-11-06 18:54:50 +00:00
parent e072572961
commit 63543343fb
1 changed files with 34 additions and 1 deletions

View File

@ -330,7 +330,40 @@
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
</source>
</source>
<p>
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:
</p>
<p><strong>Wrong:</strong></p>
<source>
for (int i = 0; i &lt; 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);
}
</source>
<p><strong>Correct:</strong></p>
<source>
HSSFCellStyle style = workbook.createCellStyle();
HSSFFont font = workbook.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
style.setFont(font);
for (int i = 0; i &lt; 10000; i++) {
HSSFRow row = sheet.createRow(i);
HSSFCell cell = row.createCell((short) 0);
cell.setCellStyle(style);
}
</source>
</section>
<anchor id="CustomColors"/>
<section><title>Custom colors</title>