带宏函数等excel解析方法

来源:互联网 发布:excel表xy轴怎么填数据 编辑:程序博客网 时间:2024/04/18 13:37

不能正常解析的excel需转换,下面是我写的例子,直接贴代码

//输入 和输入都是文件夹

public static void excelTo2003V(String excFilePath,String outFilePath,String endStr){
File[] files=readFilePath(excFilePath);//获得所有输入文件
for(int i=0;i<files.length;i++){
if(files[i].isFile()&&files[i].getPath().endsWith(endStr)){//获得所有xlsm文件
// 1.word文档转html文件
String htmlPath= Word2Html.excelToHtml(files[i].getPath());//excel转html
//2读取html。files文件夹
String htmlFiles=htmlPath.substring(0, htmlPath.indexOf("."))+".files";
System.out.println(htmlFiles);
File[] htmlFileChilds=readFilePath(htmlFiles);
List<List<List<String>>>  allSheet=new ArrayList<List<List<String>>>();//单个文件读取在写入xls会覆盖
System.out.println("================开始解析================");
for(int j=0;j<htmlFileChilds.length;j++){
if(htmlFileChilds[j].isFile()&&htmlFileChilds[j].getPath().endsWith("htm")){//满足要求 开始解析
 
List<List<String>> results= parseHtml(htmlFileChilds[j].getPath());//获得当前页面数据
allSheet.add(results);

}
}
System.out.println("================解析完成-开始写入================");
String outStreamFile=outFilePath+"/"+htmlFiles.substring(htmlFiles.lastIndexOf("\\")+1,htmlFiles.lastIndexOf("."))+"-reslut.xls";
try {
poiExportToExcel2003(allSheet, outStreamFile );
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

System.out.println("================写入完毕================");
}
}

}

 public static void main(String[] args) {
// String htmlFiles="D:\\pdfReader\\BI0901-1 中国银行利率敏感性状况历史变动表.files\\sheet002.htm";
// String excFilePath="D:/pdfReader/BI0901-1 中国银行利率敏感性状况历史变动表.xlsm";
// Excel2HtmlParse.parseHtml(htmlPath);
String outFilePath="D:\\pdfReader\\reslut";//批量分析文件夹
String htmlFiles="D:\\pdfReader\\reslut";//导出文件夹
String endStr="xlsm";//批量分析文件  类型
// System.out.println( outFilePath+"/"+htmlFiles.substring(htmlFiles.lastIndexOf("\\")+1,htmlFiles.lastIndexOf("."))+".xls");
excelTo2003V(htmlFiles,outFilePath,endStr);
}


       对于不不能正常解析的excel文件需要把错误的,2007带函数命令的转成2003版的excel文件

0 0