我使用 jxl 读取 .xls 文件,以下是我解析 xls 文件的代码。它工作正常,但问题是当我插入日期字段时,它只读取年份的最后两位数字。例如,如果我输入 12/13/2088 和 12/13/1988。它都将读取为 12/13/88。有没有解决这个问题的方法。我可以对 excel 单元格进行格式化或更改我当前的代码吗?
ArrayList listDet=new ArrayList();
HashMap mapDet=null;
HashMap primeDetails=new HashMap();
WorkbookSettings ws = null;
Workbook workbook = null;
Sheet s = null;
Cell rowData[] = null;
int rowCount = '0';
int columnCount1 = '0';
int columnCount = '0';
DateCell dc = null;
int totalSheet = 0;
try {
ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));
ws.setCellValidationDisabled(true);
workbook = Workbook.getWorkbook(fileInputStream, ws);
totalSheet = workbook.getNumberOfSheets();
//Getting Default Sheet i.e. 0
s = workbook.getSheet(0);
//Total Total No Of Rows in Sheet, will return you no of rows that are occupied with some data
System.out.println("Total Rows inside Sheet:" + s.getRows());
rowCount = s.getRows();
//Total Total No Of Columns in Sheet
System.out.println("Total Column inside Sheet:" + s.getColumns());
columnCount = s.getColumns();
//Reading Individual Row Content
for (int i = 0; i <rowCount ; i++) {
//Get Individual Row
rowData = s.getRow(i);
mapDet=new HashMap();
mapDet.put("col1",rowData[0].getContents());
mapDet.put("col2",rowData[1].getContents());
mapDet.put("col3",rowData[2].getContents());
mapDet.put("col4",rowData[3].getContents());
mapDet.put("col5",rowData[4].getContents());
mapDet.put("col6",rowData[5].getContents());
mapDet.put("col7",rowData[6].getContents());
mapDet.put("col8",rowData[7].getContents());
mapDet.put("col9",rowData[8].getContents());
listDet.add(mapDet);
}
workbook.close();
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
catch(Exception exp)
{
exp.printStackTrace();
}