Java fmt differs from Excel fmt. If Excel date format is mm/dd/yyyy, Java
will always be 00 for date since "m" is minutes of the hour.*/
strValue = new CellDateFormatter(dateFmt).format(cell.getDateCellValue());
// td.text(strValue);
}else{
XSSFCellStyle cellStyle = xssfCell.getCellStyle();
if(cellStyle!=null && cellStyle.getDataFormatString()!=null){
// String dateFmt = cell.getCellStyle().getDataFormatString();
/* strValue = new SimpleDateFormat(dateFmt).format(date); - won't work as
Java fmt differs from Excel fmt. If Excel date format is mm/dd/yyyy, Java
will always be 00 for date since "m" is minutes of the hour.*/
strValue = new HSSFDataFormatter().formatRawCellContents(cell.getNumericCellValue(), cellStyle.getDataFormat(), cellStyle.getDataFormatString());
}else{
strValue = String.valueOf(xssfCell.getNumericCellValue());
}
// xssfCell.getCellStyle().getDataFormatString();
// td.text(String.valueOf(cell.getNumericCellValue()));
}
}
td.text(strValue);
}else if(cell.getCellType()==Cell.CELL_TYPE_STRING){
td.text(cell.getStringCellValue());
}
if(sheet instanceof HSSFSheet){
HSSFSheet hssfSheet = (HSSFSheet)sheet;
HSSFCell hssfCell = (HSSFCell)cell;
HSSFCellStyle style = hssfCell.getCellStyle();
// 判断一下如果式样中有斜杠,那么写一个斜杠
HSSFPalette palette = hssfSheet.getWorkbook().getCustomPalette();
styleApplier4XLS(td,style,hssfSheet.getWorkbook(),palette);
}else{
XSSFSheet xssfSheet = (XSSFSheet)sheet;
XSSFCell xssfCell = (XSSFCell)cell;
XSSFCellStyle style = xssfCell.getCellStyle();
// 判断一下如果式样中有斜杠,那么写一个斜杠
styleApplier4XLSX(td,style,xssfSheet.getWorkbook());
}
}