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 ...
随机推荐
- css总结4:input 去掉外边框,placeholder的字体颜色、字号
1 input 标签去除外边框: 在进行webAPP开发时,input外边框非常影响美观,去除外边框方法如下: <input style="border: 0px;outline:no ...
- linux内存监控 free
free 命令详解: 执行命令后总共四行. 第一行: 列头 第二行: total 内存总数: 32881776 used 已经使用的内存数: 8324796 free 空闲的内存数: 24556980 ...
- cgroup初步分析(1)
cgroup的功能和作用不废话,直说一下cgroup的几条设计准则,有了几条设计准则的约束,就比较容易理解其中的数据结构和函数,至于源代码cgroup.c,无非是两个内容,一是task_struct. ...
- 下载特定区域内街景照片数据 | Download Street View Photos within Selected Region
作者:姜虹,刘子煜,王玥瑶,杨安琪,天靖居士 街景图片可以通过api下载,但需要提供参数,参数中的poiid.panoid.location可以用来确定位置或全景图片的ID以确定对应的街景图片.优先级 ...
- C#隐式FTPS (Implicit FTPS)
實現的方式是通過第三方程式庫實現的,當然最主要的是開源且免費,已測試過沒有問題! 目前還沒有直接取得目錄FileInfo list的方法,不過還好可以用GetDirectoryList來取得類似的結果 ...
- TSQL--删除正在运行的数据库
); SET @dbName='DB1_SNAP' BEGIN TRY --===================================== --查找当前数据库所有连接并删除 DECLARE ...
- 关于MultiDataTrigger和MultiTrigger的一些注意事项
他俩有着相同的语法. 都是在conditions中编写触发条件. 因为都是同一个触发类. 在conditions中有Property和Binding这两个属性.那么这两个可以同时使用吗?当然是不可以的 ...
- mysql相关的软件
数据库采用mysql,那么问题来了,mysql的部署是采用主备模式?主主模式?集群模式?在然后采取分库.分表模式? 其次:在外围的辅助开源软件的选择mycat?mybatis?keepalived?r ...
- Web渗透测试(xss漏洞)
Xss介绍—— XSS (cross-site script) 跨站脚本自1996年诞生以来,一直被OWASP(open web application security project) 评为十大安 ...
- c++多线程基础1(thread)
std::thread 在 <thread> 头文件中声明,因此使用 std::thread 时需要包含 <thread> 头文件. thread 构造函数: default ...