mirror of https://github.com/apache/poi.git
Updated patch from Marc from #55927 - handle date formulas too
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1614696 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8eb7e4a7f4
commit
6dd3e805e7
|
@ -293,14 +293,17 @@ public class XSSFExportToXml implements Comparator<String>{
|
||||||
if (cell.getCachedFormulaResultType() == Cell.CELL_TYPE_STRING) {
|
if (cell.getCachedFormulaResultType() == Cell.CELL_TYPE_STRING) {
|
||||||
value = cell.getStringCellValue();
|
value = cell.getStringCellValue();
|
||||||
} else {
|
} else {
|
||||||
value += cell.getNumericCellValue();
|
if (DateUtil.isCellDateFormatted(cell)) {
|
||||||
|
value = getFormattedDate(cell);
|
||||||
|
} else {
|
||||||
|
value += cell.getNumericCellValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case XSSFCell.CELL_TYPE_NUMERIC:
|
case XSSFCell.CELL_TYPE_NUMERIC:
|
||||||
if (DateUtil.isCellDateFormatted(cell)) {
|
if (DateUtil.isCellDateFormatted(cell)) {
|
||||||
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
value = getFormattedDate(cell);
|
||||||
value += sdf.format(cell.getDateCellValue());
|
|
||||||
} else {
|
} else {
|
||||||
value += cell.getRawValue();
|
value += cell.getRawValue();
|
||||||
}
|
}
|
||||||
|
@ -321,7 +324,10 @@ public class XSSFExportToXml implements Comparator<String>{
|
||||||
return elementName.matches(".*:.*")?elementName.split(":")[1]:elementName;
|
return elementName.matches(".*:.*")?elementName.split(":")[1]:elementName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getFormattedDate(XSSFCell cell) {
|
||||||
|
DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
return sdf.format(cell.getDateCellValue());
|
||||||
|
}
|
||||||
|
|
||||||
private Node getNodeByXPath(String xpath,Node rootNode,Document doc,boolean createMultipleInstances) {
|
private Node getNodeByXPath(String xpath,Node rootNode,Document doc,boolean createMultipleInstances) {
|
||||||
String[] xpathTokens = xpath.split("/");
|
String[] xpathTokens = xpath.split("/");
|
||||||
|
|
|
@ -279,8 +279,8 @@ public final class TestXSSFExportToXML extends TestCase {
|
||||||
assertNotNull(xmlData);
|
assertNotNull(xmlData);
|
||||||
assertFalse(xmlData.equals(""));
|
assertFalse(xmlData.equals(""));
|
||||||
|
|
||||||
String date = xmlData.split("<DATE>")[1].split("</DATE>")[0].trim();
|
assertEquals("2012-01-13", xmlData.split("<DATE>")[1].split("</DATE>")[0].trim());
|
||||||
assertEquals("2012-01-13", date);
|
assertEquals("2012-02-16", xmlData.split("<FORMULA_DATE>")[1].split("</FORMULA_DATE>")[0].trim());
|
||||||
|
|
||||||
parseXML(xmlData);
|
parseXML(xmlData);
|
||||||
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue