如何使用POI从excel文件单元中获取数字和字符串值,我在获取数字值错误时很容易获取字符串值 [英] How to get numeric and string value from excel file cell, using POI , i am getting error for numeric value, string value easily fetch

查看:373
本文介绍了如何使用POI从excel文件单元中获取数字和字符串值,我在获取数字值错误时很容易获取字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我正在使用String data= sheet1.getRow(row).getCell(column).getStringCellValue(); 它适用于字符串值,但显示数值错误. 因此,我必须在Excel中添加数字值,例如"34567". 还有其他方法可同时获取数字和字符串吗?

Currently i am using String data= sheet1.getRow(row).getCell(column).getStringCellValue(); It works properly for String value but displays error for numeric value. So i have to add numeric value like "34567" in excel. Is there any other method to fetch both numeric and String ?

推荐答案

当您尝试将数字单元格提取为String时,将出现错误.

You will get an error when you try to fetch the numeric cell as String.

在获取数字单元格之前,应将cellType设置为如下所示的字符串.

You should be setting the cellType as string like below, before fetching the numeric cell.

   HSSFCell yourCell = sheet1.getRow(row).getCell(column);
   yourCell.setCellType(Cell.CELL_TYPE_STRING);
   String data = yourCell.getStringCellValue();

这篇关于如何使用POI从excel文件单元中获取数字和字符串值,我在获取数字值错误时很容易获取字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆