1
我正在閱讀excel,這似乎有user defined data formats
。 例如,它有一個數據格式:"yyyy"E
,這只是顯示後跟字母E.POI-XSSF:用戶定義的數據格式
在yyyy
格式的日期現在,這種格式是不是內置的,可用的格式的一部分。
因此,似乎當我嘗試將其設置爲CellStyle
的DataFormat
時,它不起作用。
首先我讀了一個工作簿,然後從這個工作簿中創建DataFormat
。
XSSFWorkbook wb = new XSSFWorkbook(excelToRead);
XSSFDataFormat df = wb.createDataFormat();
的df
對象現在具有user defined data formats
以及(通過印刷,直到200選中)。 現在,我嘗試創建在同一工作簿中的新小區,有一個新的風格是這樣的:
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)+" ");
但是,格式不給我正確的字符串值,而不是它給我的基本的整數值的日期(如果格式不被識別,我猜是默認的)。
在XSSF中使用用戶定義格式的正確方法是什麼?
UPDATE:看來,我能夠使用其它用戶定義的格式,如yyyy
,0.0%
但不yyyy"E"
或yyyy"A"
這實際上工作!非常感謝...你有什麼想法爲什麼其他用戶格式工作,但這(yyyy「E」)之一沒有? – gaurav5430