package com.zry.excel.tools;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class ReadWriteExcel {
public static void main(String[] args){
Workbook workbook = null;
try {
InputStream is=new FileInputStream("D:/eclipses/eclipseforjquery/test.xls");
//声名一个工作薄
workbook= Workbook.getWorkbook(is);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
int intSheetCount = workbook.getNumberOfSheets();
System.out.println("总工作薄数: "+intSheetCount);
for(int i=0;i<intSheetCount;i++){
Sheet sheet = workbook.getSheet(i);
if(sheet != null){
System.out.println("当前工作薄名称: "+sheet.getName());
int rows=sheet.getRows();
int cols=sheet.getColumns();
System.out.println("行数: "+rows+"列数: "+cols);
boolean isContentLine = false;
for(int j=0;j<rows;j++){
isContentLine = false;
for (int k = 0; k < cols; k++) {
Cell cell = sheet.getCell(k,j);
if(cell != null){
Object cellVal = cell.getContents();
if(cellVal != null && !cellVal.equals("")){
System.out.print(cell.getContents()+"["+(j+1)+","+(k+1)+"]"+"\t");
isContentLine = true;
}
}
}
if(isContentLine){
System.out.println();
}
}
}
}
}
}
用jxl读取excel
最新推荐文章于 2022-08-08 11:15:02 发布