jxl主页
http://www.andykhan.com/jexcelapi/index.html
jxl似乎不支持2007,2010
jxl读取excel2010报错
jxl.read.biff.BiffException: Unable to recognize OLE stream
at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
at jxl.read.biff.File.<init>(File.java:127)
at jxl.Workbook.getWorkbook(Workbook.java:221)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at ReadExcel.readExcel(ReadExcel.java:22)
at ReadExcel.main(ReadExcel.java:64)
poi主页
http://poi.apache.org/download.html
建议使用poi,支持2003,2007,2010等,有更新
poi读取excel2010报错
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:131)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:322)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:303)
at ExcelTo.main(ExcelTo.java:12)
读取2007,2010格式的应该用XSSF
poi读取的例子
package com.urt.module.excel; import java.io.FileInputStream; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.ss.usermodel.DateUtil; public class ExcelPoi { public static void main(String[] args) { String fileToBeRead = "D:\\test.xlsx"; Workbook workbook; try { if(fileToBeRead.indexOf(".xlsx")>-1){ workbook = new XSSFWorkbook(new FileInputStream(fileToBeRead)); } else { workbook = new HSSFWorkbook(new FileInputStream(fileToBeRead)); } //HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(fileToBeRead)); //2003 创建对Excel工作簿文件的引用 //XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(fileToBeRead)); //2007,2010 创建对Excel工作簿文件的引用 Sheet sheet = workbook.getSheet("Sheet1"); // 创建对工作表的引用 int rows = sheet.getPhysicalNumberOfRows();// 获取表格的 int columns = 0; for (int r = 0; r < rows; r++) { // 循环遍历表格的行 if(r==0){ //在第一行标题行计算出列宽度,因为数据行中可能会有空值 columns = sheet.getRow(r).getLastCellNum(); continue; } String value = ""; Row row = sheet.getRow(r); // 获取单元格中指定的行对象 if (row != null) { //int cells = row.getPhysicalNumberOfCells();// 获取一行中的单元格数 //int cells = row.getLastCellNum();// 获取一行中最后单元格的编号(从1开始) for (short c = 0; c < columns; c++) { // 循环遍历行中的单元格 Cell cell = row.getCell((short) c); if (cell != null) { if (cell.getCellType() == Cell.CELL_TYPE_STRING) { // 判断单元格的值是否为字符串类型 value += cell.getStringCellValue() + ","; } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) { // 判断单元格的值是否为数字类型 //if(DateUtil.isCellDateFormatted(cell)){ // cell.getDateCellValue(); //日期型 //} value += cell.getNumericCellValue() + ","; } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) { // 判断单元格的值是否为布尔类型 value += cell.getStringCellValue() + ","; } } } } String[] str = value.split(","); System.out.println(value); } } catch (Exception e) { e.printStackTrace(); } } }
得到单元格的字符串内容,注意:有的excel里有隐藏列
//得到单元格的字符串内容 public static String getCellValue(Cell cell) { DecimalFormat df = new DecimalFormat("#"); if (cell == null) return ""; switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: if(DateUtil.isCellDateFormatted(cell)){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(cell.getDateCellValue()).toString(); //return sdf.format(DateUtil.getJavaDate(cell.getNumericCellValue())).toString(); } return df.format(cell.getNumericCellValue()); case Cell.CELL_TYPE_STRING: //System.out.println(cell.getStringCellValue()); return cell.getStringCellValue(); case Cell.CELL_TYPE_FORMULA: return cell.getCellFormula(); case Cell.CELL_TYPE_BLANK: return ""; case Cell.CELL_TYPE_BOOLEAN: return cell.getBooleanCellValue() + ""; case Cell.CELL_TYPE_ERROR: return cell.getErrorCellValue() + ""; } return ""; }
poi导出excel,不使用模板的
http://happyqing.iteye.com/blog/2075985
相关推荐
POI读写excel(.xls/.xlsx)的Demo,直接import到myeclipse即可运行。 IDE:myeclipse 9.1 含jar包
使用poi将xls格式的Excel转为xlsx,文件中的所有样式都可以完美转换,例如合并栏、背景和单元格样式等。Java源码
java spire.xls.free 快速copy excel副本或修改名称另存为、java poi操作excel(xls或者xlsx)样例 excel便捷copy jar包下载地址https://download.csdn.net/download/qq_25073261/85060851
java使用poi读取xls格式和xlsx格式的excel文件
java 基于poi的excel 格式转换器 java 基于POI 的excel格式转换器实现。 输入输出都支持XLS XLSX CSV TXT 四种类型,类接口清晰明了。
基于poi实现word/excel转换为HTML(且兼容.doc.docx.xls.xlsx) 对于简单的word Excel 转换 足够。excel转换时存在火狐浏览器不兼容乱码问题,希望多多交流。
使用poi导出excel支持xls、xlsx格式大数据导出java工具类,支持同一个单元格不同文本格式。找了好久,加上自己修改后,调试通过,发布出来分享,(调整student类位置)包含所需jar包,工具类,使用示例
struts1 poi Excel批量导入支持xls和xlsx-源码java 有需要的能帮助到
利用poi导入导出Excel xls,xlsx
java poi读取excel xls xlsx相关jar包集合,包含: dom4j-1.6.1.jar jsr173_1.0_api.jar poi-3.7-20101029.jar poi-ooxml-3.7-20101029.jar poi-ooxml-schemas-3.7-20101029.jar poi-scratchpad-3.7-20101029.jar ...
对Excel类型文件(xls,xlsx)进行批量转换CSV格式,完成文件格式无损转换,在Linux系统,通过view或其他命令查看xls、xlsx文件时会产生乱码,使用view查看csv文件不会产生乱码,因为csv格式文件是由空格和逗号进行...
maven项目解析excel .xls格式的excel文件需要HSSF支持,需要相应的poi.jar .xlsx格式的excel文件需要XSSF支持,需要poi-ooxml.jar
android 使用poi读取高版本excel, 解决以下这两个错误 java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/xml/stream/XMLEventFactory; at org.apache.poi.openxml4j.opc.internal.marshallers....
Java解析Excel的poi.jar包。支持.xls和.xlsx两种格式。可以使用它从Excel中读取数据。也可以向Excel中写数据,还可以修改Excel中的数据!
一个简单的基于Android读取xls和xlsx文件的例子,采用的POI。
Java获取excel数据所需jar包,百度的例子都是缺包的。 可以使用Workbook workbook = WorkbookFactory.create(file);的方式获取excel数据。——基于apache的poi解析。 计划是通过excel批量添加数据进数据库,后续会出...
java实现读取excel (.xlsx和.xls格式均适用)。 导入开发工具运行即可,包含所有用到的jar。
poi实现EXCEL保护工作表实例代码.zip是java使用poi实现excel保护工作表的实例代码,兼容.xls和.xlsx类型的excel,分别对其进行了处理。
poi解密excel文件实例代码.zip是java使用poi解密excel文件的实例代码,代码只实现了.xls类型的excel,.xlsx类型的excel只需把HSSF前缀的类更换成XSSF开通的前缀类即可。 本代码所实现的解密是指使用密码解密,不是...
看到现在网上excel转pdf的代码很少,在csdn上找到一个还不能用,只能做简单的转换,只好自己写了一个,代码是一个maven工程,用eclipse创建,支持单元格合并等复杂的excel,同时能同步单元格样式到pdf中。...