?? inportexcel.java
字號:
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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -