Index: src/java/org/apache/poi/ss/util/CellUtil.java =================================================================== --- src/java/org/apache/poi/ss/util/CellUtil.java (revision 1715581) +++ src/java/org/apache/poi/ss/util/CellUtil.java (working copy) @@ -172,20 +172,18 @@ /** * This method attempt to find an already existing CellStyle that matches what you want the * style to be. If it does not find the style, then it creates a new one. If it does create a - * new one, then it applies the propertyName and propertyValue to the style. This is necessary - * because Excel has an upper limit on the number of Styles that it supports. + * new one, then it applies the properties to the style. This is necessary because Excel has + * an upper limit on the number of Styles that it supports. * *@param workbook The workbook that is being worked with. - *@param propertyName The name of the property that is to be changed. - *@param propertyValue The value of the property that is to be changed. + *@param properties A HashMap of properties to be added to a cell style. *@param cell The cell that needs it's style changes */ - public static void setCellStyleProperty(Cell cell, Workbook workbook, String propertyName, - Object propertyValue) { + public static void setCellStyleProperty(Cell cell, Workbook workbook, Map properties) { CellStyle originalStyle = cell.getCellStyle(); CellStyle newStyle = null; Map values = getFormatProperties(originalStyle); - values.put(propertyName, propertyValue); + values.putAll(properties); // index seems like what index the cellstyle is in the list of styles for a workbook. // not good to compare on! @@ -209,6 +207,24 @@ cell.setCellStyle(newStyle); } + /** + * This method calls setCellStyleProperty(Cell, Workbook, Map) with a single + * property. If more than one property is to be set, it is better to call with a HashMap rather + * than a single property since each property added will search for a matching style and + * potentially create an unnecessary intermediate CellStyle. + * + *@param workbook The workbook that is being worked with. + *@param propertyName The name of the property that is to be changed. + *@param propertyValue The value of the property that is to be changed. + *@param cell The cell that needs it's style changes + */ + public static void setCellStyleProperty(Cell cell, Workbook workbook, String propertyName, + Object propertyValue) { + Map values = new HashMap(); + values.put(propertyName, propertyValue); + setCellStyleProperty(cell, workbook, values); + } + /** * Returns a map containing the format properties of the given cell style. *