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 ...
随机推荐
- Alternative to iPhone device ID (UDID)
Alternative to iPhone device ID (UDID) [duplicate] up vote10down votefavorite 3 Possible Duplicate:U ...
- Linq 左连接 left join
Suppose you have a tblRoom and tblUserInfo. Now, you need to select all the rooms regardless of whet ...
- 树形DP-----HDU4003 Find Metal Mineral
Find Metal Mineral Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Other ...
- 转 Delphi中XLSReadWrite控件的使用(2)---基本应用
unit Main; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...
- android开关控件Switch和ToggleButton
序:今天项目中用到了开关按钮控件,查阅了一些资料特地写了这篇博客记录下. 1.Switch <Switch android:id="@+id/bt" android:layo ...
- IOS GPS跟踪备注
CLLocationManager还提供了如下类方法来判断当前设备的定位相关服务状态. Ø + locationServicesEnabled:返回当前定位服务是否可用. Ø + deferredLo ...
- asp.net winform 界面传值
第一种 //form1 //静态传值 public static string Chuanzhi; string Chuanzhi = textbox.text; //form2 string Chu ...
- VMware虚拟机下安装CentOS系统超详细教程
链接:https://jingyan.baidu.com/article/fdffd1f8736173f3e98ca1e3.html 1.步骤一.工具准备 1.物理计算机一台 配置要求: 操作系统:w ...
- 【BZOJ3622】已经没什么好害怕的了 容斥原理+dp
Description Input Output Sample Input 4 2 5 35 15 45 40 20 10 30 Sample Output 4 HINT 输入的2*n个数字保证全不相 ...
- 解决 Github用户名 变为 invalid-email-address 问题
解决 Github用户名 变为 invalid-email-address 问题 If the identity used for this commit is wrong, you can fix ...