在线求助关于NPIO读取Excel文件的问题~~~~~~~~~~~~~~~~~~~~~~
using( Workbook wb=new HSSFWorkbook(fs))
{
Sheet sheet= wb.GetSheetAt(0);
string title1 = sheet.GetRow(0).GetCell(0).StringCellValue;
string title2 = sheet.GetRow(0).GetCell(1).StringCellValue;
string title3 = sheet.GetRow(0).GetCell(2).StringCellValue;
string title4 = sheet.GetRow(0).GetCell(3).StringCellValue;
string sql = null;
string homephone = null;
string carnum = null;
string carenginnum = null;
int rowsnum=0;
DateTime buytime;
if (title1 == "固定电话" && title2 == "车号" && title3 == "车架号" && title4 == "购买时间")
{
int rowcount = sheet.LastRowNum;
for (int i = 1; i <= rowcount; i++)
{
//导入execl表单元格的数据
homephone = sheet.GetRow(i).GetCell(0).StringCellValue == null ? null : sheet.GetRow(i).GetCell(0).StringCellValue; ;
carnum = sheet.GetRow(i).GetCell(1).StringCellValue == null ? null : sheet.GetRow(i).GetCell(1).StringCellValue;
carenginnum = sheet.GetRow(i).GetCell(2).StringCellValue == null ? null : sheet.GetRow(i).GetCell(2).StringCellValue;
buytime =sheet.GetRow(i).GetCell(3).DateCellValue;
在读取单元格之前我已经判断了是否为空值,可是为什么单元格一有空值的时候就表错呢

[解决办法]
我没用过这个控件,但是我觉得应判断sheet.GetRow(i).GetCell(0)是否为null,而不是它的StringCellValue为null。