这里只是读取Excel表的code
package com.cn;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ExcelTest {
private static final String FILEPATH = "C:\\Users\\GiGon\\Desktop\\test.xls";
public static void main(String[] args) {
Sheet sheet = null;
try {
File file = new File(FILEPATH);
//判断文件是否存在
if(!file.exists()){
return;
}
//获取sheet 实例
sheet = ExcelTest.readExcel(FILEPATH);
//获取行
int rows = sheet.getRows();
//获取列
int columns = sheet.getColumns();
//创建arrayList
List<String[]> sheetList = new ArrayList<>();
for(int i = 0; i < rows; i++){
//创建columns长的数组
String[] columnsArray = new String[columns];
for(int j = 0; j < columns; j++){
Cell cell = sheet.getCell(j,i);
columnsArray[j] = cell.getContents();
}
sheetList.add(columnsArray);
}
for (int i = 0; i < sheetList.size(); i++){
String[] strArray = sheetList.get(i);
System.out.println(Arrays.asList(sheetList));
System.out.println(strArray[2]);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
}
}
/**
* 读取Excel 表
*/
public static Sheet readExcel(String xlsPath) throws Exception {
FileInputStream fileIn = null;
//根据指定的文件输入流导入Excel从而产生Workbook对象
Workbook workbook = null;
fileIn = new FileInputStream(xlsPath);
workbook = Workbook.getWorkbook(fileIn);
// //获取Excel文档中的第一个表单
String[] sheetNames = workbook.getSheetNames();
jxl.Sheet sheet = workbook.getSheet(sheetNames[0]);
fileIn.close();
return sheet;
}
}