poi读取excel2010
package com.icss.test;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ImportExcelToDatabase {
public static void main(String[] args) {
//String excel2003_2007 = Common.STUDENT_INFO_XLS_PATH;
String excel2010 = "C:\\Users\\gls\\Desktop\\移动手机号码测试格式.xlsx";
List<NodeAddress> list = readExcel(excel2010);
if(list!=null){
for (NodeAddress n : list) {
System.out.println("time="+n.getTime()+"地区="+n.getArea()+"县市="+n.getCounty()+"区域="+n.getDistrict()
+"乡镇="+n.getVillage()+"电话号码="+n.getTelephone());
}
}
}
private static List<NodeAddress> readExcel(String path){
List<NodeAddress> list = new ArrayList<NodeAddress>();
try {
InputStream is = new FileInputStream(path);
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
NodeAddress nodeAddress = null;
//读sheet
for (int numSheet = 0; numSheet < xssfWorkbook.getNumberOfSheets(); numSheet++) {
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
if(xssfSheet==null){
continue;
}
//读行
for(int rowNum=1;rowNum<=xssfSheet.getLastRowNum();rowNum++){
XSSFRow xssfRow = xssfSheet.getRow(rowNum);
if(xssfRow!=null){
nodeAddress = new NodeAddress();
XSSFCell time = xssfRow.getCell(0);
XSSFCell area = xssfRow.getCell(1);
XSSFCell county = xssfRow.getCell(2);
XSSFCell district = xssfRow.getCell(3);
XSSFCell village = xssfRow.getCell(4);
XSSFCell telehone = xssfRow.getCell(5);
nodeAddress.setTime(getValue(time));
nodeAddress.setArea(getValue(area));
nodeAddress.setCounty(getValue(county));
nodeAddress.setDistrict(getValue(district));
nodeAddress.setVillage(getValue(village));
nodeAddress.setTelephone(getValue(telehone));
list.add(nodeAddress);
}
}
return list;
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
private static String getValue(XSSFCell xssfRow){
if(xssfRow.getCellType()==xssfRow.CELL_TYPE_BOOLEAN){
return String.valueOf(xssfRow.getBooleanCellValue());
}else if(xssfRow.getCellType()==xssfRow.CELL_TYPE_NUMERIC){
return String.valueOf(xssfRow.getNumericCellValue());
}else{
return String.valueOf(xssfRow.getStringCellValue());
}
}
}
poi读取excel2010的更多相关文章
- POI读取/写入Excel文件
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...
- 使用jxl,poi读取excel文件
作用:在java后台添加一个方法,读取导入的excel内容,根据需要返回相应的sql语句,以完成对临时表的插入操作. 使用jxl读取excel文件 package com.sixthf.bi.sapp ...
- POI读取Excel内容格式化
在用POI读取Excel内容时,经常会遇到数据格式化的问题. 比如:数字12365会变为12365.0;字符串数字123也会变为123.0,甚至会被变为科学计数法.另外日期格式化也是一个头疼的问题.其 ...
- java使用poi读取ppt文件和poi读取excel、word示例
java使用poi读取ppt文件和poi读取excel.word示例 http://www.jb51.net/article/48092.htm
- POI 读取word (word 2003 和 word 2007) (转)
最近在给客户做系统的时候,用户提出需求,要能够导入 word 文件,现在 microsoft word 有好几个版本 97.2003.2007的,这三个版本存储数据的格式上都有相当大的差别,而现在 9 ...
- JAVA使用POI读取EXCEL文件的简单model
一.JAVA使用POI读取EXCEL文件的简单model 1.所需要的jar commons-codec-1.10.jarcommons-logging-1.2.jarjunit-4.12.jarlo ...
- lucent检索技术之创建索引:使用POI读取txt/word/excel/ppt/pdf内容
在使用lucent检索文档时,必须先为各文档创建索引.索引的创建即读出文档信息(如文档名称.上传时间.文档内容等),然后再经过分词建索引写入到索引文件里.这里主要是总结下读取各类文档内容这一步. 一. ...
- jspsmart(保存文件)+poi(读取excel文件)操作excel文件
写在前面: 项目环境:jdk1.4+weblogic 需求:能上传excel2003+2007 由于项目不仅需要上传excel2003,还要上传excel2007,故我们抛弃了jxl(只能上传exce ...
- POI读取excel文件。
1) poi读取现成.xls文件,不需要自己建立.xls ====ReadExcel类==== package cust.com.excelToDataTest; import java.io.F ...
随机推荐
- The Three Models of ASP.NET MVC Apps
12 June 2012 by Dino Esposito by Dino Esposito We've inherited from the original MVC pattern a ra ...
- 【Head First Java 读书笔记】(一)基本概念
Java的工作方式 你要做的事情就是会编写源代码 Java的程序结构 类存于源文件里面 方法存在类中 语句存于方法中 剖析类 当Java虚拟机启动执行时,它会寻找你在命令列中所指定的类,然后它会锁定像 ...
- 四则运算(Java) 陈志海 邓宇
目录 Github项目地址 PSP表格 功能要求 题目 功能(已全部实现) 效能分析 设计实现过程 数值生成 算式生成 问题集生成 设计实现过程 代码说明 测试运行 代码覆盖率 项目小结 Github ...
- MongoDB整理笔记のDump & Restore
备份 [root@localhost bin]# ./mongodump -d my_mongodb connected to: 127.0.0.1 DATABASE: my_mongodb t ...
- Ajax GET
$ajax的post请求提交方式: Controller: @RequestMapping("/emps") @ResponseBody public Msg getEmps(@R ...
- session相关
判断session是否已失效: HttpSession session=request.getSession(false); getSession(boolean)相比于getSession()更安全 ...
- plantix插件工具,eclipse工具
代码修改后部署流程: 修改代码-->自动构建工作空间(将修改的代码或配置文件复制到classes文件夹)-->发布到tomcat环境中-->重启服务器运行 常见报错:java.lan ...
- 857. Minimum Cost to Hire K Workers
There are N workers. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now w ...
- 【转】c#中@的3种作用
源地址:https://www.cnblogs.com/linkbiz/p/6380814.html
- iOS 开发之 GCD 不同场景使用
header{font-size:1em;padding-top:1.5em;padding-bottom:1.5em} .markdown-body{overflow:hidden} .markdo ...