inportexcel.java
来自「数据库设计的一个lab」· Java 代码 · 共 90 行
JAVA
90 行
import java.io.File;
import java.io.IOException;
import jxl.*;
import jxl.read.biff.BiffException;
/*
读一个Excel文件
*/
public class InportExcel {
private String filename;
private Cell[][] cell;
private String[][] strCell;
private int rows;
private int cols;
private String sheetName;
private String[] sheetNames;
private Sheet[] sheet;
public InportExcel(String filename)
{
this.filename=filename;
}
//return cell对象
public Cell[][] getCells(){return cell;}
//return strCell
public String[][] getStrings(){return strCell;}
//return the name of the sheet
public String getSheetName(){return sheetName;}
public String[] getSheetNames(){return sheetNames;}
//return the number of the rows
public int getRows(){return rows;}
//return the number of the columns
public int getCols(){return cols;}
//return sheets
public Sheet[] getSheets()
{
return sheet;
}
//read a workbook of one sheet
public void read()
{
try {
//get a workbook
Workbook workbook = Workbook.getWorkbook(new File(filename));
//get the sheet
//Sheet sheet = workbook.getSheet(0);
sheet=workbook.getSheets();
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void read(Sheet sheet)
{
rows = sheet.getRows(); //get the number of rows
cols = sheet.getColumns(); //get the number of columns
cell =new Cell[rows][cols];
strCell= new String[rows][cols];
//put the content of each cell into the strCell
for (int i=0;i<=rows-1;i++)
{
for (int j=0;j<=cols-1;j++)
{
cell[i][j] = sheet.getCell(j,i);
strCell[i][j]=cell[i][j].getContents();
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?