--- poi-3.9/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java 2012-11-25 13:27:35.000000000 +0100 +++ poi-3.9/src/java/org/apache/poi/hssf/usermodel/HSSFCellStyle.java 2013-10-22 11:18:32.000000000 +0200 @@ -18,9 +18,13 @@ package org.apache.poi.hssf.usermodel; +import java.util.Arrays; +import java.util.List; + import org.apache.poi.hssf.model.InternalWorkbook; import org.apache.poi.hssf.record.ExtendedFormatRecord; import org.apache.poi.hssf.record.FontRecord; +import org.apache.poi.hssf.record.FormatRecord; import org.apache.poi.hssf.record.StyleRecord; import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.ss.usermodel.CellStyle; @@ -106,8 +110,42 @@ public final class HSSFCellStyle impleme * @see org.apache.poi.hssf.usermodel.HSSFDataFormat * @return the format string or "General" if not found */ + + private static ThreadLocal lastDateFormat = new ThreadLocal() { + @Override + protected Short initialValue() { + return Short.MIN_VALUE; + } + }; + + private static ThreadLocal> lastFormats = new ThreadLocal>() { + @Override + protected List initialValue() { + return null; + } + }; + + private static ThreadLocal getDataFormatStringCache = new ThreadLocal() { + @Override + protected String initialValue() { + return null; + } + }; + public String getDataFormatString() { - return getDataFormatString(_workbook); + if (getDataFormatStringCache.get() != null) { + if (lastDateFormat.get() == getDataFormat() && _workbook.getFormats().equals(lastFormats.get())) { + return getDataFormatStringCache.get(); + } + } + + lastFormats.set(_workbook.getFormats()); + lastDateFormat.set(getDataFormat()); + + getDataFormatStringCache.set(getDataFormatString(_workbook)); + + return getDataFormatStringCache.get(); + } /** * Get the contents of the format string, by looking up @@ -828,6 +866,11 @@ public final class HSSFCellStyle impleme // Handle matching things if we cross workbooks if(_workbook != source._workbook) { + + lastDateFormat.set(Short.MIN_VALUE); + lastFormats.set(null); + getDataFormatStringCache.set(null); + // Then we need to clone the format string, // and update the format record for this short fmt = (short)_workbook.createFormat(source.getDataFormatString() ); @@ -874,4 +917,5 @@ public final class HSSFCellStyle impleme } return false; } + }