java - 无法使用 Jexcel API 读取单元格值
问题描述
我正在尝试通过 JExecel Api 读取 .xls 文件。我可以通过使用cell.getContents()轻松读取一些列数据。但是有些列给了我神秘的值 1,但列类型看起来像Date。所以我检查了那些列类型并发现它们是数字类型。所以我将那些单元格投射到NumberCell中。但是输出看起来仍然很神秘 1。
Workbook workbook = null;
try {
workbook = Workbook.getWorkbook("StandardReport.xls");
Sheet sheet = workbook.getSheet(0);
Cell[] cellRow = sheet.getColumn(0);
for (int row = 4; row < cellRow.length; row++) {
String id = cellRow[row].getContents().trim();
if (id.isEmpty() == false) {
Cell cell1 = sheet.getCell(1, row);
Cell cell2 = sheet.getCell(2, row);
Cell cell3 = sheet.getCell(3, row);
System.out.println(cell1.getContents()+"");
System.out.println(cell2.getContents()+"");
System.out.println(cell3.getContents()+"");
if (cell3.getType() == CellType.NUMBER) {
NumberCell date=(NumberCell)cell3;
System.out.println(date.getContents()+"");
}
/*if (cell3.getType() == CellType.BOOLEAN) {
System.out.println("2");
}
if (cell3.getType() == CellType.BOOLEAN_FORMULA) {
System.out.println("3");
}
if (cell3.getType() == CellType.DATE_FORMULA) {
System.out.println("4");
}
if (cell3.getType() == CellType.EMPTY) {
System.out.println("5");
}
if (cell3.getType() == CellType.ERROR) {
System.out.println("6");
}
if (cell3.getType() == CellType.FORMULA_ERROR) {
System.out.println("7");
}
if (cell3.getType() == CellType.LABEL) {
System.out.println("8");
}
if (cell3.getType() == CellType.NUMBER) {
System.out.println("9");
}
if (cell3.getType() == CellType.NUMBER_FORMULA) {
System.out.println("11");
}
if (cell3.getType() == CellType.STRING_FORMULA) {
System.out.println("12");
}*/
}
}
} catch (IOException | BiffException ex) {
StaticAccess.showMessageDialog("Failed!!", ex);
}
解决方案
推荐阅读
- neo4j - 如何根据 Cypher 中顶点属性的相等性检查创建边?
- amazon-dynamodb - 限制从 AWS GUI 访问 Dynamodb 项目
- c++ - 为什么即使两个向量不同,比较运算符“==”也会返回“YES”?
- python - 根据数组中的唯一值拆分数组
- python - 如何在 for 循环中再次读取输入?
- javascript - 无法使用 jquery 从 textarea 获取文本
- bash - 从脚本 A 调用脚本 B 中定义的函数 - 不执行脚本 B 的主体
- r - 如何删除数据中应该有数字的文本
- php - 出现验证错误时,似乎无法让表单输入保持不变
- corda - 我可以创建一个流程来将状态迁移到新版本而不是使用合约升级吗?