java遍历Excel行
来源:互联网 发布:全球软件行业市场规模 编辑:程序博客网 时间:2024/05/16 15:12
背景:从数据库导出数据到Excel文档,再从Excel中截取需要的数据列形成sql,去操作sql。
废话少说,直接贴代码
public static void test() throws Exception { InputStream is = new FileInputStream("C:\\Users\\Administrator\\Desktop\\update.xlsx"); Workbook wb = WorkbookFactory.create(is); is.close(); Sheet sheet = wb.getSheetAt(0); int trLength = sheet.getLastRowNum(); log.info("最大行号:{}", trLength); StringBuilder sql = new StringBuilder(); for (int i = 1; i <= trLength; i++) { Row row = sheet.getRow(i); String cardLength = ""; //修正报错:Cannot get a text value from a numeric cell if(row.getCell(8)!=null){ row.getCell(8).setCellType(Cell.CELL_TYPE_STRING); cardLength = row.getCell(8).getStringCellValue(); } String bankBinCode = ""; if(row.getCell(13)!=null){ row.getCell(13).setCellType(Cell.CELL_TYPE_STRING); bankBinCode = row.getCell(13).getStringCellValue(); } sql.append("=======此处拼装SQL========="); } log.info(sql.toString()); FileOutputStream fos = new FileOutputStream(new File("C:\\Users\\Administrator\\Desktop\\update-sql.txt")); byte b[] = sql.toString().getBytes(); fos.write(b); fos.close(); }
引用jar包:
poi-3.14.jar
poi-ooxml-3.14.jar
poi-ooxml-schemas-3.14.jar
xmlbeans-2.6.0.jar
遇到的问题:
1、java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
是由缺失xmlbeans-2.6.0.jar包导致。
2、Cannot get a text value from a numeric cell
需要先设置cell为String类型:
if(row.getCell(8)!=null){
row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
cardLength = row.getCell(8).getStringCellValue();
}
感谢csdn同行们的帮助:
http://blog.csdn.net/liucheng417/article/details/52727018
http://blog.csdn.net/ysughw/article/details/9288307
poi-ooxml-3.14.jar
poi-ooxml-schemas-3.14.jar
xmlbeans-2.6.0.jar
遇到的问题:
1、java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
是由缺失xmlbeans-2.6.0.jar包导致。
2、Cannot get a text value from a numeric cell
需要先设置cell为String类型:
if(row.getCell(8)!=null){
row.getCell(8).setCellType(Cell.CELL_TYPE_STRING);
cardLength = row.getCell(8).getStringCellValue();
}
感谢csdn同行们的帮助:
http://blog.csdn.net/liucheng417/article/details/52727018
http://blog.csdn.net/ysughw/article/details/9288307
阅读全文
0 0
- java遍历Excel行
- java读取遍历excel
- EXCEL 行遍历,备用
- java使用poi遍历Excel保存到容器中
- POI遍历Excel
- 遍历excel文件
- VC++遍历Excel
- VC++遍历Excel
- php 遍历 excel文件。
- EXCEL遍历当前SHEET有效行,统计附值
- 遍历和JAVA遍历
- Java的poi技术遍历Excel时进行空Cell,空row,判断
- C#中如何遍历Excel
- word,excel宏遍历文件
- 遍历指定文件夹中的Excel
- java 遍历
- Java遍历
- Java Excel 操作excel
- leetcode 661. Image Smoother
- cscope 使用时打开新的窗口
- No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '***' is theref
- 我来试试
- uboot启动第二阶段1
- java遍历Excel行
- 关于排列组合算法的心得
- 【python】复杂对象的创建过程与转化为json
- jsonp请求实例原生和jquery
- 最详细开发者账号申请流程,不看后悔
- Vue学习笔记一
- 趣味推理题 动动好久没有认真思考的脑袋
- cs231n笔记--到底什么是梯度消散
- 在windows上安装mongodb(二)