注意: 不支持 xlsx
添加依赖
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
源码:
package test;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import java.io.File;
public class Excel {
public static void main(String[] args) throws Exception {
File f = new File("d://test.xls");
try {
Workbook wb=Workbook.getWorkbook(f);
int Num = wb.getNumberOfSheets();
for (int i = 0; i < Num; i++) {
Sheet sheet = wb.getSheet(i);
Sheet s = wb.getSheet(i);
int row = s.getRows();
int col = s.getColumns();
for(int i1=0; i1<row;i1++) {
for(int j=0;j<col;j++) {
Cell c =s.getCell(j, i1);
System.out.println(c.getContents());
//String text = c.getContents();
}
}
}
} catch (Exception e) {
e.getMessage();
}
System.out.println("completed");
}
}
网友评论