---
title: "org.apache.poi 读excel空列跳过的问题"
author: "godlogin"
date: "2011-12-07T23:37:54Z"
tags: []
categories: ["Web前端"]
slug: "org-apache-poi-excel"
draft: false
lastmod: "2011-12-07T23:37:54Z"
id: 1297239
url: "https://godlogin.iteye.com/blog/1297239"
---

用org.apache.poi的包做excel导入，无意间发现如果excel文件中有空列，空列后面的数据全部读不到。查来查去原来是HSSFRow提供两个方法：getPhysicalNumberOfCells和getLastCellNum。

getPhysicalNumberOfCells 是获取不为空的列个数。

getLastCellNum 是获取最后一个不为空的列是第几个。

同样，HSSFSheet获取行也有类似两个方法，如果excel数据中存在空行或空列，必须用getLast**的方法才能完全读取数据。