Java 中用POI lib读excel文件
来源:互联网 发布:123d建模软件 编辑:程序博客网 时间:2024/06/06 07:49
import org.apache.poi.hpsf.*
import org.apache.poi.hssf.usermodel.HSSFCell
import org.apache.poi.hssf.usermodel.HSSFRichTextString
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.poifs.filesystem.DocumentInputStream
import org.apache.poi.poifs.filesystem.POIFSFileSystem
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.IOException
import java.io.InputStream
import java.util.Iterator
public class test{
public void getContent(xlsPath) {
InputStream inputStream = new FileInputStream (xlsPath)
POIFSFileSystem fileSystem = new POIFSFileSystem (inputStream)
HSSFWorkbook workBook = new HSSFWorkbook (fileSystem)
HSSFSheet sheet = workBook.getSheetAt (0)
Iterator<HSSFRow> rows = sheet.rowIterator ()
while (rows.hasNext ())
{
HSSFRow row = rows.next ()
//display row number in the console.
System.out.println ("Row No.: " + row.getRowNum ())
//once get a row its time to iterate through cells.
Iterator<HSSFCell> cells = row.cellIterator ()
while (cells.hasNext ())
{
HSSFCell cell = cells.next ()
System.out.println ("Cell No.: " + cell.getCellNum ())
/*
* Now we will get the cell type and display the values
* accordingly.
*/
if (cell.getCellType () == HSSFCell.CELL_TYPE_NUMERIC)
{
// cell type numeric.
System.out.println ("Numeric value: " + cell.getNumericCellValue ())
}
else if (cell.getCellType () == HSSFCell.CELL_TYPE_STRING )
{
// cell type string.
HSSFRichTextString richTextString = cell.getRichStringCellValue ()
System.out.println ("String value: " + richTextString.getString ())
}
else {
// types other than String and Numeric.
System.out.println ("Type not supported.")
}
}
}
}
}
API doc: http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Cell.html
- Java 中用POI lib读excel文件
- java中用poi读取Excel文件
- java中用poi导入excel文件到数据库总结
- JAVA中用POI组件访问EXCEL文档
- poi读excel文件
- apahce poi excel lib
- Java POI读写Excel文件
- java poi导出excel文件
- java+poi解析excel文件
- java poi读取excel文件
- Java--POI读取excel文件
- java poi读取excel文件
- java 读取Excel文件(POI)
- java poi Excel文件导入
- Java Poi操作Excel文件
- java POI 读取EXCEL文件
- Struts中用Apache POI作成Excel文件,并下载
- Java中用Apache POI生成excel和word文档
- Project Management Orientation - Define the project team (Concepts -1)
- tomcat6配置JNDI数据库连接池常易出现的问题
- 确认删除用法
- VC从文件中加载图片
- TCP/IP编程基础——超时、多路复用、非阻塞
- Java 中用POI lib读excel文件
- UltraChart属性设置个人理解(补充完善……)
- derby真的不支持SQL级的分页吗? (转)
- OSWORKFLOW学习笔记2
- 可以用来查找主窗体的代码
- Groovy Switch
- mysql 存储过程写法(转)
- linux设备驱动概述
- 手机报 精文摘抄