import java.io.IOException;
import java.io.OutputStream;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import javax.xml.validation.Validator;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFMap;
import org.apache.poi.xssf.usermodel.XSSFRow;
case XSSFCell.CELL_TYPE_BOOLEAN: value += cell.getBooleanCellValue(); break;
case XSSFCell.CELL_TYPE_ERROR: value = cell.getErrorCellString(); break;
case XSSFCell.CELL_TYPE_FORMULA: value = cell.getStringCellValue(); break;
- case XSSFCell.CELL_TYPE_NUMERIC: value += cell.getRawValue(); break;
+ case XSSFCell.CELL_TYPE_NUMERIC:
+ if (DateUtil.isCellDateFormatted(cell)) {
+ DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ value += sdf.format(cell.getDateCellValue());
+ } else {
+ value += cell.getRawValue();
+ }
+ break;
default: ;
}
* Compares two xpaths to define an ordering according to the XML Schema
*
*/
+ @Override
public int compare(String leftXpath, String rightXpath) {
int result = 0;
String xml = os.toString("UTF-8");
assertNotNull(xml);
- assertTrue(!xml.equals(""));
+ assertFalse(xml.equals(""));
String docente = xml.split("<DOCENTE>")[1].split("</DOCENTE>")[0].trim();
String nome = xml.split("<NOME>")[1].split("</NOME>")[0].trim();
String xml = os.toString("UTF-8");
assertNotNull(xml);
- assertTrue(!xml.equals(""));
+ assertFalse(xml.equals(""));
String docente = xml.split("<DOCENTE>")[1].split("</DOCENTE>")[0].trim();
String nome = xml.split("<NOME>")[1].split("</NOME>")[0].trim();
String xmlData = os.toString("UTF-8");
assertNotNull(xmlData);
- assertTrue(!xmlData.equals(""));
+ assertFalse(xmlData.equals(""));
String a = xmlData.split("<A>")[1].split("</A>")[0].trim();
String b = a.split("<B>")[1].split("</B>")[0].trim();
assertEquals("19", chf);
}
}
+
+ public void testFormulaCells_Bugzilla_55927() throws Exception {
+ XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("55927.xlsx");
+
+ for (POIXMLDocumentPart p : wb.getRelations()) {
+
+ if (!(p instanceof MapInfo)) {
+ continue;
+ }
+ MapInfo mapInfo = (MapInfo) p;
+
+ XSSFMap map = mapInfo.getXSSFMapById(1);
+
+ assertNotNull("XSSFMap is null", map);
+
+ XSSFExportToXml exporter = new XSSFExportToXml(map);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ exporter.exportToXML(os, true);
+ String xmlData = os.toString("UTF-8");
+
+ assertNotNull(xmlData);
+ assertFalse(xmlData.equals(""));
+
+ String date = xmlData.split("<DATE>")[1].split("</DATE>")[0].trim();
+ assertEquals("2012-01-13", date);
+ }
+ }
}