1.首先导入jxl的jar包(依赖)
<dependencies>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
</dependencies>
2.代码如下:
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import java.io.File;
import java.io.IOException;
public class Excel{
public static void main(String[] args) throws Exception {
File file=new File("C:\\Users\\99248\\Desktop\\demo.xls");
Workbook.getWorkbook(file);
Workbook wb=Workbook.getWorkbook(file);
Sheet sheet=wb.getSheet("Sheet1");
for (int i = 0; i < sheet.getRows(); i++) {
for (int j = 0; j < sheet.getColumns(); j++) {
Cell cell=sheet.getCell(j,i);
System.out.print(cell.getContents()+"\t");
}
System.out.println();
}
wb.close();
}
}
视频地址:https://www.bilibili.com/video/BV1nz4y1R7Px?p=1&share_medium=iphone&share_plat=ios&share_session_id=5D2B6965-06D9-4D44-8FB8-12406C15B059&share_source=WEIXIN&share_tag=s_i×tamp=1657525594&unique_k=S1rc77R&vd_source=4aad20cea963d4c78552ddc959b8cde3