关于解决java读取excel文件遇空行抛空指针的问题 !
关于解决java读取excel文件遇空行抛空指针的问题 !
package exceRead; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.DecimalFormat; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcleReadNullRow {
public static void getType(XSSFCell cell) {
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getRichStringCellValue().getString() + "|");
// System.out.print("|");
break;
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cell)) {
System.out.print(String.valueOf(cell.getDateCellValue()) + "|");
} else {
System.out.print(cell.getNumericCellValue() + "|");
}
// System.out.print("|");
break;
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue() + "|");
// System.out.print("|");
break;
default:
} } public static void main(String[] args) throws FileNotFoundException, IOException { ExcleUtil excle = new ExcleUtil();
String value = "";
String filePath = "C:\\Users\\ty\\Documents\\工作簿1.xlsx";
File file = new File(filePath);
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(file));
XSSFSheet sheet = wb.getSheetAt(0);
int rowcount = sheet.getLastRowNum() - sheet.getFirstRowNum();
int rowcount1 = sheet.getPhysicalNumberOfRows();
System.out.println(rowcount1);
System.out.println("该excle的总行数为:" + (rowcount + 1) + "行 !"); /*
* int rows = sheet.getLastRowNum(); for(int i = 0; i < rows+1; i++){ //
* List<String> rowData = new ArrayList<String>(); Row row =
* sheet.getRow(i); if(row != null){ int cols = row.getLastCellNum();
* for(int j = 0; j < cols; j++){ XSSFCell cell = (XSSFCell)
* row.getCell(j); ExcleReadNullRow.getType(cell); } //
* System.out.println();
*
* }
*/ for (int i = 0; i < rowcount + 1; i++) {
Row row = sheet.getRow(i);
if (row == null) {
System.out.println("this row is null ----------------------");
continue; } else {
for (int j = row.getFirstCellNum(); j < row.getLastCellNum(); j++) {
XSSFCell cell = (XSSFCell) row.getCell(j);
System.out.print("| ");
if (cell != null) {
ExcleReadNullRow.getType(cell);
} else { continue; }
}
System.out.println(); } } }
}
excle文件中的内容 :

java打印出出的内容 :
关于解决java读取excel文件遇空行抛空指针的问题 !的更多相关文章
- Java读取Excel文件的几种方法
Java读取 Excel 文件的常用开源免费方法有以下几种: 1. JDBC-ODBC Excel Driver 2. jxl.jar 3. jcom.jar 4. poi.jar 简单介绍: 百度文 ...
- java读取excel文件的代码
如下内容段是关于java读取excel文件的内容,应该能对各朋友有所用途. package com.zsmj.utilit; import java.io.FileInputStream;import ...
- JAVA 读取excel文件成List<Entity>
package com.fsinfo.common.utils; import com.fsinfo.modules.enterprise.entity.EnterpriseRecordEntity; ...
- java 读取Excel文件并数据持久化方法Demo
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util ...
- java读取excel文件数据导入mysql数据库
这是我来公司的第二周的一个小学习任务,下面是实现过程: 1.建立maven工程(方便管理jar包) 在pom.xml导入 jxl,mysql-connector 依赖 可以在maven仓库搜索 2.建 ...
- JAVA读取EXCEL文件异常Unable to recognize OLE stream
异常: jxl.read.biff.BiffException: Unable to recognize OLE stream at jxl.read.biff.CompoundFile.<in ...
- Java 读取Excel 文件内容
在一个项目中,有一个需求,是把excel文件的内容转换为xml格式展示.在学习如何操作的过程中,首先是如何获取excel文件,其中操作的代码如下: 1.首先是导入需要的 jar, 下载地址:https ...
- java读取excel文件内容
1.导入依赖JAR包 <!-- jxl 操作excel --> <dependency> <groupId>org.jxls</groupId> < ...
- Java 读取excel 文件 Unable to recognize OLE stream 错误
原因:不支出读取 excel 2007 文件(*.xlsx).只支持 excel 2003 (*.xls).
随机推荐
- GO富集分析柱状图
target_gene_id <- unique(read.delim("miRNA-gene interactions.txt")$EntrezID) # BiocInst ...
- 版本控制工具(下)——Git的远程仓库、分支管理与其它操作
预备知识: SSH协议参考资料:http://blog.csdn.net/vevenlcf/article/details/43273405 图解公钥和私钥:http://blog.csdn.net/ ...
- 初步安装配置虚拟机、Ubuntu、git、vim、码云项目
内容 虚拟机软件:Oracle VM VirtualBox 系统:Ubuntu 配置:git:码云;vim 过程 下载安装VirtualBox.ubuntu 根据链接-- 基于VirtualBox安装 ...
- 20155339 2016-2017-2 《Java程序设计》第十周学习总结
20155339 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 计算机网络概述 在计算机网络中,现在命名IP地址的规定是IPv4协议,该协议规定每个IP地址 ...
- kali2.0下JAVA安装
参考网址:http://www.blackmoreops.com/2013/10/26/how-to-install-java-jdk-in-kali-linux/ 1.下载javase,http:/ ...
- idea 严重: Error configuring application listener of class org.springframework.web.context.Context 后面省略
根本原因:jar文件没有同步发布到自己项目的lib目录中 解决方案:把之前在这个位置的jar文件,put into 到 /WEB-INF/lib 目录下即可
- mfs分布式系统从理论简介到实战部署
文章前面想说的话:这篇博客写出来真是有点累到了,本来昨天就基本就写好了,放在草稿里面,今天打开就没有了!!唉,就尼玛离我而去了,只有重写,然后中间虚拟机还“爆炸”重启又搞了一会,不容易呀!!希望各位博 ...
- 安装Vue.js的方法有三种
1 使用独立的版本 在Vue.js官网上直接下载,在script标签里引用. 2 使用CND方法(不推荐) 3 NMP 方法 在用Vue.js构建大型应用的时候推荐使用NMP安装方法,NMP能很好的和 ...
- Selenium2+python自动化-文件上传
前言 文件上传是web页面上很常见的一个功能,自动化成功中操作起来却不是那么简单. 一般分两个场景:一种是input标签,这种可以用selenium提供的send_keys()方法轻松解决:另外一种非 ...
- 第三篇 Python关于mysql的API--pymysql模块, mysql事务
python关于mysql的API--pymysql模块 pymysql是Python中操作MySQL的模块,其使用方法和py2的MySQLdb几乎相同. 模块安装 pip install pymys ...