Top Description Constructors Methods
org.apache.poi.hssf.usermodel

public Class HSSFOptimiser

extends Object
Class Inheritance
Imports
java.util.HashSet, org.apache.poi.hssf.record.ExtendedFormatRecord, .FontRecord, .StyleRecord, org.apache.poi.hssf.record.common.UnicodeString, org.apache.poi.ss.usermodel.Cell, .CellType, .Row

Excel can get cranky if you give it files containing too many (especially duplicate) objects, and this class can help to avoid those. In general, it's much better to make sure you don't duplicate the objects in your code, as this is likely to be much faster than creating lots and lots of excel objects+records, only to optimise them down to many fewer at a later stage. However, sometimes this is too hard / tricky to do, which is where the use of this class comes in.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static boolean
isUserDefined(HSSFWorkbook workbook, int index)

public static void
optimiseCellStyles(HSSFWorkbook
The workbook in which to optimise the cell styles
workbook
)

Goes through the Wokrbook, optimising the cell styles by removing duplicate ones, and ones that aren't used.

public static void
optimiseFonts(HSSFWorkbook
The workbook in which to optimise the fonts
workbook
)

Goes through the Workbook, optimising the fonts by removing duplicate ones.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

HSSFOptimiserback to summary
public HSSFOptimiser()

Method Detail

isUserDefinedback to summary
private static boolean isUserDefined(HSSFWorkbook workbook, int index)
optimiseCellStylesback to summary
public static void optimiseCellStyles(HSSFWorkbook workbook)

Goes through the Wokrbook, optimising the cell styles by removing duplicate ones, and ones that aren't used. For best results, optimise the fonts via a call to optimiseFonts(HSSFWorkbook) first.

Parameters
workbook:HSSFWorkbook

The workbook in which to optimise the cell styles

optimiseFontsback to summary
public static void optimiseFonts(HSSFWorkbook workbook)

Goes through the Workbook, optimising the fonts by removing duplicate ones. For now, only works on fonts used in HSSFCellStyle and HSSFRichTextString. Any other font uses (eg charts, pictures) may well end up broken! This can be a slow operation, especially if you have lots of cells, cell styles or rich text strings

Parameters
workbook:HSSFWorkbook

The workbook in which to optimise the fonts