Cannot get a STRING value from a NUMERIC cell

Cannot get a STRING value from a NUMERIC cell
错误一:
导入Excel表格数据,该列设置数据类型为String,输入数据是int类型
解决方法:cell.setCellType(CellType.STRING);
错误二:日期类型需要定义格式
解决方法如下:

        for(int i = 1 ; i <= totalRowNum ; i++)
    {
        //获得第i行对象
        Row row = sheet.getRow(i);
        //获得获得第i行第0列的 String类型对象
        Cell cell = row.getCell((short)0);
        id = (int) cell.getNumericCellValue();
        
        cell = row.getCell((short)1);
        **cell.setCellType(CellType.STRING);**
        barcode = cell.getStringCellValue().toString();
        
        cell = row.getCell((short)2);
        bookname = cell.getStringCellValue().toString();
        
        cell = row.getCell((short)3);
        typeid = (int) cell.getNumericCellValue();
        
        cell = row.getCell((short)4);
        author = cell.getStringCellValue().toString();
        
        cell = row.getCell((short)5);
        ISBN = cell.getStringCellValue().toString();
        
        cell = row.getCell((short)6);
        publisher = cell.getStringCellValue().toString();
        
        cell = row.getCell((short)7);
        price =  (float) cell.getNumericCellValue();
        
        cell = row.getCell((short)8);
        page = (int) cell.getNumericCellValue();
        
        cell = row.getCell((short)9);
        if (cell != null)
        {
            if (cell.getCellTypeEnum() != CellType.STRING && HSSFDateUtil.isCellDateFormatted(cell))
            {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

                Date date = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());
                intime = sdf.format(date);

                System.out.println(intime);
            }
        }
        
        
        cell = row.getCell((short)10);
        introduc = cell.getStringCellValue().toString();
        
        cell = row.getCell((short)11);
        bcount = (int) cell.getNumericCellValue();
        
        cell = row.getCell((short)12);
        operator = cell.getStringCellValue().toString();
        
        
        //获得一个数字类型的数据
        //cell = row.getCell((short)1);
        //latitude = (int) cell.getNumericCellValue();
        book.setId(id);
        book.setBarcode(barcode);
		book.setBookname(bookname);
		book.setTypeid(typeid);
		book.setAuthor(author);
		book.setISBN(ISBN);
		book.setPublisher(publisher);
		book.setPrice(price);
		book.setPage(page);
		book.setIntime(intime);
		book.setIntroduc(introduc);;
		book.setBcount(bcount);
		book.setOperator(operator);
        bookDao.add(book);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值