poi 中读取和写入excel 方法
2013-12-07 20:39
288 查看
1 excel读取和写入的方法
2
package com.poi.importxls; import java.io.FileInputStream; import java.io.FileOutputStream; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.formula.functions.Value; public class ImportExcelTest { public static void main(String[] args) throws Exception { FileInputStream inputStream = null; HSSFWorkbook book = null; HSSFRow row = null; HSSFCell cell = null; inputStream = new FileInputStream("d:/docs/22李荣光 - 副本.xls"); book = new HSSFWorkbook(inputStream); HSSFSheet sheet = book.getSheetAt(0); int rows = sheet.getLastRowNum(); System.out.println("行数:"+rows); for (int i = 0; i <= rows; i++) { if(i>=20) continue; row = sheet.getRow(i); int cols = row.getLastCellNum(); System.out.println(i+"行列数"+cols); for (int j = 0; j < cols; j++) { cell = row.getCell(j); Object obj; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_NUMERIC: obj = cell.getNumericCellValue(); System.out.println(j+"列"+obj); break; case HSSFCell.CELL_TYPE_STRING: obj = cell.getStringCellValue(); System.out.println(j+"列"+obj); break; default: break; } } } book.write(new FileOutputStream("d:/docs/22李荣光 - 副本-2.xls")); } }
2
相关文章推荐
- POI操作Excel,读取,写入
- POI读取和写入Excel
- java SpringMVC中 POI读取数据库数据并写入Excel表格中,并实现下载功能
- java中用poi处理Excel表格之写入(2003和2007通用方法)
- Java模块 -- 读取Excel文件写入数据库 Mybatis , POI , JXL
- Java读取大数据量Excel的方法(POI)
- java使用poi读取excel内容方法实例
- java 通过poi 读取Excel 写入sqlser mysql
- VC++ 中操作Excel文档的方法,读取,查询,写入,修改,删除
- java使用POI读取properties文件并写到Excel的方法
- POI读取Excel数据类型的判断方法
- poi读取excel时数字类型的解决方法
- VC++ 中操作Excel文档的方法,读取,查询,写入,修改,删除
- poi读取Excel时日期为数字 的解决方法
- poi开源jar包操作excel时读取单元格的标准方法
- Java+Poi 读取Excel做数据导入时获取cell值的方法
- 用POI来读取/写入完整的Excel文件(一)
- Java用POI读取解析Excel时,遇到科学计数法的解决方法
- poi 学习之使用 Apche poi 读取数据库中的数据并写入Excel
- poi读取写入excel【未完,待续】