1、读取excel2003
@Test
//读取excel2003
public void testCreateXLS(){
try {
String path = "f:\\app\\iotest\\n.xls.doc";
String postfix = (path.trim().lastIndexOf(".") == -1)?"":path.substring(path.trim().lastIndexOf(".") + 1);
if("xls".equalsIgnoreCase(postfix) || "xlsx".equalsIgnoreCase(postfix)){
//创建工作簿
HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(path));
//创建sheet
HSSFSheet sheet = wb.getSheetAt(0);
StringBuffer sb = new StringBuffer();
if(sheet != null){
//sheet.getLastRowNum();最后一行
for(int i=0;i<sheet.getLastRowNum();i++){
if(sheet.getRow(i) != null){
HSSFRow row = sheet.getRow(i);
//row.getLastCellNum();一行中的最后一列
for(int j=0;j<row.getLastCellNum();j++){
HSSFCell cell = row.getCell(j);
String cellValue = "";
if(cell != null){
switch(cell.getCellType()){
case HSSFCell.CELL_TYPE_NUMERIC:
cellValue = String.valueOf(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_STRING:
cellValue = cell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_BLANK:
cellValue = cell.getStringCellValue();
break;
default:
break;
}
}
sb.append(cellValue.trim() + " ");
}
}
sb.append("\n");
}
System.out.println(sb.toString());
}
wb.close();
}else{
System.out.println("不支持的文件类型");
}
} catch (IOException e) {
e.printStackTrace();
}
}
分享到:
相关推荐
Java 操作Excel poi读写excel,所需要的jar包 https://blog.csdn.net/u014646662/article/details/83217382
本案例中利用Apache Poi读取Excel用法,源码注释详细基本用法!
java poi读取excel 2007 存贮在list中
将excel文件中的内容通过java文件读取出来,包括总行数,列数,单元格内容,合并单元格,行高,列宽,图片等信息。
java读写Excel,POI.JAR,Word内容读取
主要介绍了Java POI读取excel中数值精度损失问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Java用poi读取excel文件Java用poi读取excel文件Java用poi读取excel文件
利用POI读取excel写入到word 利用POI读取excel写入到word 利用POI读取excel写入到word,压缩包里包含了jar包
java读取excel 表格数据。 public static void main(String[] args) { String[][] content=POIExcelUtils.read("E:\\1.xlsx"); for(int i=0;i;i++) { if(content[i]!=null){ for(int j=0;j[i].length;j...
NULL 博文链接:https://mazilaidaige.iteye.com/blog/1725205
这个项目实现的功能是读取excel文件中的数据,解析并写入数据库。 读取的excel文件位于项目目录下的 excel\0805.xlsx 使用IntelliJ IDEA开发此项目 使用MYSQL查看数据库 在MYSQL中运行项目db目录下的sql文件,创建...
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 ...
poi读写excel,poi总结; poi读写excel,poi总结 poi读写excel,poi总结
java poi读取excel表格数据一整套jar包 包括(dom4j和xmlbeans包)
1.java使用poi生成excel插入图表曲线 2.demo包含完成jar包 3.主要用途是过滤数据自动生成曲线图
Java通过POI读取Excel遍历数据,根本word模板批量生成word文档,demo可运行,可根据需求修改
通过poi读取excel表格信息,可以实现对97,2003,2007,2010等excel表格的读取
我分享的资源分必须为0!这里面所有读取Excel的poi包都有,虽然版本不是都相同,还有两个必须的,但是不是poi的包,我试过了,没有这两个包,虽然代码可能没错,但是运行会出错。
压缩包里面有poi相关的jar包,以及我在使用poi时候导入jar包遇到问题总结和一个小demo。