Java读取Excel
pom依赖
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
Java代码
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import java.io.File;
import java.io.IOException;
public class ReadExcel {
public static void main(String[] args) throws IOException, BiffException {
File file = new File("d:\\test.xls");
Workbook rwb = Workbook.getWorkbook(file);
Sheet rs = rwb.getSheet(0);
int colums = rs.getColumns();
int rows = rs.getRows();
System.out.println("colums :" + colums + " rows:" + rows);
for (int j = 0; j < rows; j++) {
String name = rs.getCell(0, j).getContents();
String phon = rs.getCell(1, j).getContents();
System.out.println(" name:" + name + " age:" + phon);
}
}
}
打印显示
Excel显示
备注
由于jxl是支持excel2003版本 xsl,所以新建和保存Excel时要选择Excle 2003版本