环境:
commons-codec-1.10.jar
commons-collections4-4.1.jar
commons-io-2.11.0.jar
commons-logging-1.2.jar
curvesapi-1.04.jar
dom4j-1.6.1.jar
jxl.jar
log4j-1.2.17.jar
poi-3.9-20121203.jar
poi-ooxml-3.9-20121203.jar
poi-ooxml-schemas-3.9-20121203.jar
xml-apis.jar
xmlbeans-2.3.0.jar
public class fileTest2 {
public String[][] text = new String[40000][4];
public int count=0;
public int i_errNum = 0;
@Test()
public void getFile(){
//设定文件存放路径
String dir_path = "/Users/file/Desktop/files";
File file = new File(dir_path);
//获取文件夹下所有文件
File[] files = file.listFiles();
//遍历文件
for(File file2:files){
System.out.println(file2.getName());
//解析当前文件
readColumn_xlsx(dir_path+"/"+file2.getName(),file2.getName());
}
fileOut(this.text);
}
/**
* 针对不同excel版本使用不同的工具类
* HSSFWorkbook:解析03之前的excel文件,即文件后缀为.xls
* XSSFWorkbook:解析07版本excel文件,即文件后缀为.xlsx
* @param filePath 文件全路径
* @param name 文件名
*/
public void readColumn_xlsx(String filePath,String name){
String xlsxType = "xlsx";
String xlsType = "xls";
File e_file = new File(filePath);
try {
InputStream in = new FileInputStream(e_file);
Workbook workbook = null;
if (filePath.endsWith(xlsxType)){
workbook = new XSSFWorkbook(in);
}else if (filePath.endsWith(xlsType)){
workbook = new HSSFWorkbook(in);
}
//正式解析excel内容
readExcel(workbook,filePath,name);
} catch (Excep