如何用JXL 2.6.12罐子来读取Excel文件 [英] How to read excel file using JXL 2.6.12 jar
本文介绍了如何用JXL 2.6.12罐子来读取Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我加入jxl.jar在我的Eclipse项目,它看到皈依错误的Dalvik格式到控制台。
在控制台错误显示:
[2010-08-02十九点十一分22秒 - TestApp]麻烦写输出:不应该发生的。
[2010-08-02十九点十一分22秒 - TestApp]转换为的Dalvik格式失败,出现错误2
code是确定
下面是我的code:
进口的java.io.File;
进口java.io.IOException异常;
进口jxl.Cell;
进口jxl.CellType;
进口jxl.Sheet;
进口jxl.Workbook;
进口jxl.read.biff.BiffException;
公共类READEXCEL {
私人字符串INPUTFILE;
公共无效setInputFile(字符串INPUTFILE){
this.inputFile = INPUTFILE;
}
公共无效的read()抛出IOException异常{
文件inputWorkbook =新的文件(INPUTFILE);
工作簿瓦;
尝试 {
W = Workbook.getWorkbook(inputWorkbook);
//获取第一张
苫布苫布= w.getSheet(0);
//循环第10列和行
对于(INT J = 0; J< sheet.getColumns(); J ++){
的for(int i = 0; I< sheet.getRows();我++){
电池单元= sheet.getCell(J,I);
单元格类型类型= cell.getType();
如果(cell.getType()== CellType.LABEL){
的System.out.println(我有一个标签
+ cell.getContents());
}
如果(cell.getType()== CellType.NUMBER){
的System.out.println(我得到了一些
+ cell.getContents());
}
}
}
}赶上(BiffException E){
e.printStackTrace();
}
}
}
反正是有解决这个问题呢?
谢谢 Mintu
解决方案
单元格类型类型= cell.getType();
如果(cell.getType()== cell.LABEL){
的System.out.println(我有一个标签+ cell.getContents());
}
如果(cell.getType()== cell.NUMBER){
的System.out.println(我得到了许多+ cell.getContents());
}
使用细胞
不是单元格类型
。
When I am adding jxl.jar in my eclipse project, it saw convertion error to dalvik format into the console.
Error display in console:
[2010-08-02 19:11:22 - TestApp] trouble writing output: shouldn't happen
[2010-08-02 19:11:22 - TestApp] Conversion to Dalvik format failed with error 2
Code is ok
Below is my code:
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ReadExcel {
private String inputFile;
public void setInputFile(String inputFile) {
this.inputFile = inputFile;
}
public void read() throws IOException {
File inputWorkbook = new File(inputFile);
Workbook w;
try {
w = Workbook.getWorkbook(inputWorkbook);
// Get the first sheet
Sheet sheet = w.getSheet(0);
// Loop over first 10 column and lines
for (int j = 0; j < sheet.getColumns(); j++) {
for (int i = 0; i < sheet.getRows(); i++) {
Cell cell = sheet.getCell(j, i);
CellType type = cell.getType();
if (cell.getType() == CellType.LABEL) {
System.out.println("I got a label "
+ cell.getContents());
}
if (cell.getType() == CellType.NUMBER) {
System.out.println("I got a number "
+ cell.getContents());
}
}
}
} catch (BiffException e) {
e.printStackTrace();
}
}
}
Is there anyway to solve this problem?
Thanks Mintu
解决方案
CellType type = cell.getType();
if (cell.getType() == cell.LABEL) {
System.out.println("I got a label " + cell.getContents());
}
if (cell.getType() == cell.NUMBER) {
System.out.println("I got a number " + cell.getContents());
}
USE cell
NOT CellType
.
这篇关于如何用JXL 2.6.12罐子来读取Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文