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 Difference Between @Helpers and @Functions In WebMatrix
from: http://www.mikesdotnetting.com/article/173/the-difference-between-helpers-and-functions-in-web ...
- UVa 10245 The Closest Pair Problem (分治)
题意:给定 n 个点,求最近两个点的距离. 析:直接求肯定要超时的,利用分治法,先把点分成两大类,答案要么在左边,要么在右边,要么一个点在左边一个点在右边,然后在左边或右边的好求,那么对于一个在左边一 ...
- vi常用快捷键汇总
第一部分:光标移动.复制粘贴.查找替换 [Ctrl] + [f] 下一页 [Ctrl] + [b] 上一页 0或[home] 到行首 $或[end] 到行尾 G 到最后一行 gg ...
- DataType--数值类型
SQL Server数值类型可以分为精确数字类型和近似数字类型精确数字BIT/SMALLINT/TINYINT/INT/BIGINTNUMERIC/DECIMAL/SMALLMONEY/MONEY 近 ...
- C# / .Net Core 访问MongoDb库
话不多说直接上代码 连接字符串: { "AppSettings": { "mongodb": "mongodb://用户名:密码@IP地址:端口号&q ...
- .NET Core Api 集成 swagger
废话不多讲 第一步 当然是要通过 NuGet 安装第三方插件 swagger 程序包管理器控制台,安装命令:Install-Package Swashbuckle.AspNetCore -Pre 第 ...
- 生成MySql数据库的数据字典代码参考
Code: /** * 生成mysql数据字典 */ //配置数据库 $dbserver = "127.0.0.1"; $dbusername = "root" ...
- Socket 简易静态服务器 WPF MVVM模式(三)
ViewModels类 这个类其实就是个大杂烩,什么都可以用 这个类没有什么东西,最多的就是写一下xaml页面的逻辑控制,开启关闭监听 using System; using System.Colle ...
- windows下安装newman
1.下载安装node.js,下载地址::https://nodejs.org/en/download/,这里我下载的为v10.15.0-x64.msi,下载后直接安装即可,安装完后可输入node -v ...
- Launch VINS example (Euroc dataset) in RTAB-MAP
$ roslaunch rtabmap_ros euroc_datasets.launch args:="-d RGBD/CreateOccupancyGrid false Odom/Str ...