I am reading an excel , which seems to have user defined data formats
.
for example it has a data format : "yyyy"E
, which just displays the date in yyyy
format followed by the letter E.
Now, this format is not a part of the built in ,available formats.
So, it seems that when i try to set this as DataFormat
of a CellStyle
, it doesn't work.
First i read a workbook and then create the DataFormat
from this workbook.
XSSFWorkbook wb = new XSSFWorkbook(excelToRead);
XSSFDataFormat df = wb.createDataFormat();
the df
object now has the user defined data formats
as well (checked by printing till 200).
Now, I try to create a new cell in the same workbook, with a new style like this:
XSSFCell cellTemp = row.createCell(0);
XSSFCellStyle styleTemp = wb.createCellStyle();
styleTemp.setDataFormat(df.getFormat(cell.getCellStyle().getDataFormatString()));
cellTemp.setCellStyle(styleTemp);
cellTemp.setCellValue(cell.getStringCellValue());
System.out.print(formatter.formatCellValue(cellTemp)+" ");
But, the formatter does not give me the correct string value, instead it gives me the underlying Integer value of the date (which i guess is the default if the format is not recognized).
What is the correct way to use user defined formats in XSSF?
UPDATE: It seems that i am able to use other user defined formats like yyyy
, 0.0%
but not yyyy"E"
or yyyy"A"