import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.IOException
import java.util.logging.Logger
import org.apache.poi.hssf.usermodel.HSSFCell
import org.apache.poi.hssf.usermodel.HSSFSheet
import org.apache.poi.hssf.usermodel.HSSFWorkbook
public class TestExcel {
private static final Logger LOG = Logger.getLogger(TestExcel.class.getName())
public static void main(String[] args) {
//excel file location
String filePath = "C:\\A.xls"
HSSFWorkbook book
HSSFSheet sheet
try {
book = new HSSFWorkbook(new FileInputStream(filePath))
sheet = book.getSheetAt(0)
//row is 4 and cell is 2.
for (int row = 0row <4row++) {
for (int cell = 0cell <2cell++) {
HSSFCell hssfCell = sheet.getRow(row).getCell(cell)
if(hssfCell != null){
System.out.println("[row" + (row+1) + ",cell" + (cell+1) + "]:" + hssfCell.toString())
}
else{
//using waring to show the null message.
LOG.warning("[row" + (row+1) + "族清,cell" + (cell+1) + "]:null")
}
}
}
}
catch (FileNotFoundException e) {
LOG.info("can't find the file:" + filePath)
}
catch (IOException e) {
LOG.info("IOException:" + e.getMessage())
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)