[英]Getting wrong date Format while using apache poi DataFormatter on cell
我已經使用 Apache poi DataFormatter 類來獲取與 Excel 表中給出的日期相同的日期。 但在下面的情況下,它失敗了。
例如,如果我將日期指定為 2017 年 9 月 19 日,則它會變為 17 年 9 月 19 日。
我使用下面的代碼來獲取與 Excel 表中給出的日期值相同的日期值。
DataFormatter df = new DataFormatter();
String stringCellValue = df.formatCellValue(cell).toString();
XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);
XSSFSheet sheet = wb.getSheetAt(0);
XSSFRow row = sheet.getRow(0);
XSSFCell cell = row.getCell((short)0);
short x = wb.createDataFormat().getFormat("dd/m/yyyy;@");
CellStyle dateCellFormat = wb.createCellStyle();
dateCellFormat.setDataFormat(x);
cell.setCellStyle(dateCellFormat);
DataFormatter df = new DataFormatter();
String stringCellValue = df.formatCellValue(cell).toString();
System.out.println(stringCellValue);
此代碼為輸入19/12/2017
打印19/12/2017
,為19/09/2017
打印19/9/2017
。 也許您可以調整我的代碼以使您的代碼正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.