|
|
@@ -49,6 +49,7 @@ import org.apache.poi.ss.util.NumberToTextConverter; |
|
|
|
import org.apache.poi.util.LocaleUtil; |
|
|
|
import org.apache.poi.util.POILogFactory; |
|
|
|
import org.apache.poi.util.POILogger; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@@ -306,10 +307,17 @@ public class DataFormatter implements Observer { |
|
|
|
if(formatStr == null || formatStr.trim().length() == 0) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return getFormat(cell.getNumericCellValue(), formatIndex, formatStr); |
|
|
|
return getFormat(cell.getNumericCellValue(), formatIndex, formatStr, isDate1904(cell)); |
|
|
|
} |
|
|
|
|
|
|
|
private Format getFormat(double cellValue, int formatIndex, String formatStrIn) { |
|
|
|
private boolean isDate1904(Cell cell) { |
|
|
|
if (cell == null || ! (cell.getSheet().getWorkbook() instanceof XSSFWorkbook) ) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
return ((XSSFWorkbook) cell.getSheet().getWorkbook()).isDate1904(); |
|
|
|
} |
|
|
|
|
|
|
|
private Format getFormat(double cellValue, int formatIndex, String formatStrIn, boolean use1904Windowing) { |
|
|
|
localeChangedObservable.checkForLocaleChange(); |
|
|
|
|
|
|
|
// Might be better to separate out the n p and z formats, falling back to p when n and z are not set. |
|
|
@@ -338,7 +346,7 @@ public class DataFormatter implements Observer { |
|
|
|
if (DateUtil.isADateFormat(formatIndex, formatStr) && |
|
|
|
// don't try to handle Date value 0, let a 3 or 4-part format take care of it |
|
|
|
((Double)cellValueO).doubleValue() != 0.0) { |
|
|
|
cellValueO = DateUtil.getJavaDate(cellValue); |
|
|
|
cellValueO = DateUtil.getJavaDate(cellValue, use1904Windowing); |
|
|
|
} |
|
|
|
// Wrap and return (non-cachable - CellFormat does that) |
|
|
|
return new CellFormatResultWrapper( cfmt.apply(cellValueO) ); |
|
|
@@ -788,7 +796,7 @@ public class DataFormatter implements Observer { |
|
|
|
} |
|
|
|
return generalNumberFormat; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Performs Excel-style date formatting, using the |
|
|
|
* supplied Date and format |
|
|
@@ -875,7 +883,7 @@ public class DataFormatter implements Observer { |
|
|
|
// Is it a date? |
|
|
|
if(DateUtil.isADateFormat(formatIndex,formatString)) { |
|
|
|
if(DateUtil.isValidExcelDate(value)) { |
|
|
|
Format dateFormat = getFormat(value, formatIndex, formatString); |
|
|
|
Format dateFormat = getFormat(value, formatIndex, formatString, use1904Windowing); |
|
|
|
if(dateFormat instanceof ExcelStyleDateFormatter) { |
|
|
|
// Hint about the raw excel value |
|
|
|
((ExcelStyleDateFormatter)dateFormat).setDateToBeFormatted(value); |
|
|
@@ -890,7 +898,7 @@ public class DataFormatter implements Observer { |
|
|
|
} |
|
|
|
|
|
|
|
// else Number |
|
|
|
Format numberFormat = getFormat(value, formatIndex, formatString); |
|
|
|
Format numberFormat = getFormat(value, formatIndex, formatString, use1904Windowing); |
|
|
|
if (numberFormat == null) { |
|
|
|
return String.valueOf(value); |
|
|
|
} |