知道 大家都知道用poi读取xls  当时有时候 必需要读取xlsx  如今我把我做測试的demo分享给大家

package com.lt.main;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List; import org.apache.poi.hssf.usermodel.HSSFCell;
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.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import com.lt.util.DBUtil;
import com.lt.util.Oracle; public class ReadMain { public static void readFile(File file){ Connection con = null;
PreparedStatement ps = null;
String sql = "insert into t_xls(mobile) values(?)";
int count = 0;
try {
con = DBUtil.getConnection();
ps = con.prepareStatement(sql); InputStream is = new FileInputStream(file);
XSSFWorkbook wb = new XSSFWorkbook(is);
XSSFCell cell = null;
for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) {
XSSFSheet st = wb.getSheetAt(sheetIndex);
for (int rowIndex = 0; rowIndex <= st.getLastRowNum(); rowIndex++) {
XSSFRow row = st.getRow(rowIndex);
cell = row.getCell(0);
cell.setCellType(XSSFCell.CELL_TYPE_STRING);
count++;
ps.setString(1, cell.getStringCellValue());
ps.addBatch(); if(count % 10000 == 0){
ps.executeBatch();
}
}
}
ps.executeBatch(); }catch (Exception e) {
e.printStackTrace();
}finally{
DBUtil.close(ps);
DBUtil.close(con);
}
} public static void main(String[] args) {
DBUtil.startProxool();
readFile(new File("C:\\Documents and Settings\\Administrator\\桌面\\22.xlsx")); }
}

里面会涉及把内容写入到数据库的

poi读取xlsx的更多相关文章

  1. 使用poi读取xlsx中的数据

    excel中的内容见下图: 详细代码: package dataprovider; import java.io.FileInputStream; import java.io.InputStream ...

  2. apache poi 读取xlsx并导出为json(没考虑xls)

    1.用到的jar包:fastjson-1.2.9.poi(poi-3.15.poi-ooxml-3.15.poi-ooxml-schemas-3.15.xmlbeans-2.6.0.commons-c ...

  3. 用 Apache POI 读取 XLSX 数据

    最近因为项目的原因,需要从一些 Microsoft Office Excel 文件读取数据并加载到数据库. Google了一下方法,发现其实可以用的 Java 第三方库很多,最著名的是 Apache ...

  4. 使用POI读取xlsx文件,包含对excel中自定义时间格式的处理

    package poi; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExcepti ...

  5. 使用POI读取/创建Execl(.xlsx)文件

    最近项目中用到了解析Execl表格的功能,在网上百度了一下自己写了一个小Demo.由于项目中使用的是Execl2007,就是后缀为.xlsx的,所以只研究了解析和创建Execl2007的文件,解析Ex ...

  6. 【POI】使用POI处理xlsx的cell中的超链接 和 插入图片 和 设置打印区域

    使用POI对xlsx中插入超链接和 插入图片 package com.it.poiTest; import java.awt.image.BufferedImage; import java.io.B ...

  7. POI读取/写入Excel文件

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...

  8. JAVA使用POI读取EXCEL文件的简单model

    一.JAVA使用POI读取EXCEL文件的简单model 1.所需要的jar commons-codec-1.10.jarcommons-logging-1.2.jarjunit-4.12.jarlo ...

  9. lucent检索技术之创建索引:使用POI读取txt/word/excel/ppt/pdf内容

    在使用lucent检索文档时,必须先为各文档创建索引.索引的创建即读出文档信息(如文档名称.上传时间.文档内容等),然后再经过分词建索引写入到索引文件里.这里主要是总结下读取各类文档内容这一步. 一. ...

随机推荐

  1. HDU - 3341 Lost&#39;s revenge(AC自己主动机+DP)

    Description Lost and AekdyCoin are friends. They always play "number game"(A boring game b ...

  2. Eclipse 出错 Error:Could not create the Java Virtual Machine Error:A fatal exception has occurred

    提示如下: scala compile server. error:could not create the java machine.Error: A fatal exception has occ ...

  3. C#添加水印

    using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Secu ...

  4. 【习题 3-6 UVA - 232】Crossword Answers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟题.注意场宽为3 [代码] #include <bits/stdc++.h> using namespace std ...

  5. 如何在hadoop中控制map的个数 分类: A1_HADOOP 2015-03-13 20:53 86人阅读 评论(0) 收藏

    hadooop提供了一个设置map个数的参数mapred.map.tasks,我们可以通过这个参数来控制map的个数.但是通过这种方式设置map的个数,并不是每次都有效的.原因是mapred.map. ...

  6. jquery-12 jquery的ajax如何使用

    jquery-12 jquery的ajax如何使用 一.总结 一句话总结:就是$.get()和$.post()方法的使用,看参考手册就好,与php的交互. 1.删除元素的时候如何设置删除特效? ani ...

  7. (五)RabbitMQ消息队列-安装amqp扩展并订阅/发布Demo(PHP版)

    原文:(五)RabbitMQ消息队列-安装amqp扩展并订阅/发布Demo(PHP版) 本文将介绍在PHP中如何使用RabbitMQ来实现消息的订阅和发布.我使用的系统依然是Centos7,为了方便, ...

  8. [Recompose] Add Lifecycle Hooks to a Functional Stateless Component using Recompose

    Learn how to use the 'lifecycle' higher-order component to conveniently use hooks without using a cl ...

  9. [Angular] NgRx/effect, why to use it?

    See the current implementaion of code, we have a smart component, and inside the smart component we ...

  10. Java中a=a+b 与 a+=b差别

    一般觉得a=a+b的运行效率是低于a+=b的,由于它多进行了一步中间变量的操作,并且会多占用一个变量的空间.而Java编译器默认对其进行了优化,优化之后两条语句都当做 a+=b来运行了,所以实际上是没 ...