今天在写代码的时候发现,无论怎么读取excel时候,自带加上了小数点。
原因:
虽然excel中设置的都是文本,但是数字文本还被读错,如“1”取成“1.0”, 加上下面这句,临时把它当做文本来读取。
解决方法:
user= new User();
HSSFCell userid = hssfRow.getCell(0);
加上这句话转换: userid.setCellType(userid.CELL_TYPE_STRING);
打印出来测试已经没有了小数点:System.out.println(getValue(userid));
贴代码:
package com.hmy.ssh.myMethod;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import com.hmy.ssh.bean.User;
//import com.b510.common.Common;
//import com.b510.excel.vo.Student;
/*
* 1.通过java读取excel文档存储信息,必须先写好行数、对应的列。
* 2.用户选择路径就可以
*
* */
public class ReadUserExcel {
public static void main(String[] args){
ReadUserExcel readExcel=new ReadUserExcel();
try {
List
exam=readExcel.