【现象】
共有2行数据
[张三1, 1.8312345678E10, 张三2, 1.8312345679E10]
【解决方法】
v.add(row.getCell(1)+"");
修改为:
v.add(row.getCell(1).getRawValue());
解决后输出结果为:
共有2行数据
[张三1, 18312345678, 张三2, 18312345679]
【完整代码】
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Vector;import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;public class ReadExcel {public Vector<String> readExcel(String filePath) throws Exception {Vector<String> v = new Vector<String>(); // 存放读取出来的姓名和电话InputStream iStream = new FileInputStream(filePath);XSSFWorkbook workbook =new XSSFWorkbook(iStream);// sheet row column 下标都是从0开始的XSSFSheet sheet = workbook.getSheetAt(0);int rowNumber = sheet.getPhysicalNumberOfRows();System.out.println("共有" + rowNumber + "行数据");for (int i = 0; i < rowNumber; i++) {XSSFRow row = sheet.getRow(i);v.add(row.getCell(0)+"");v.add(row.getCell(1).getRawValue());}// 操作完成时,关闭对象,释放占用的内存空间if (iStream != null) {iStream.close();}return v;}/*** @param args* @throws Exception*/public static void main(String[] args) throws Exception {String filePath = "D:\\1\\抽奖数据2.xlsx";ReadExcel readExcel = new ReadExcel();System.out.println(readExcel.readExcel(filePath).toString());}
}