Java中关于读取Excel

tong_data tong_data 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
一段小程序,用java读取Excel数据的。
package com.inAndOut;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

class ReadIN {
private List<Integer> list = new ArrayList<Integer>();// 存放整数
public List<Integer> input() throws IOException {
BufferedReader in = null;
String str = null;
try {
in = new BufferedReader(new FileReader("./你好.xls"));
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("这是打开文件错误!");
}
str = in.readLine();// 抛弃第一行
while ((str = in.readLine()) != null) {
String[] str2 = str.trim().split("\\s+");//通过空格切分
// 程序运行时出现错误 主要错误
for (int i = 1; i < str2.length; i++) {// 从第二个单元格开始 list.add(Integer.parseInt(str2[i]));
}
}
in.close();
return list;
}
}
public class Yunxing{
public static void main(String[] args){
ReadIN ri=new ReadIN();
List<Integer> list = new ArrayList<Integer>();
list=ri.input();
System.out.println(list);//出现错误
}
}


你好.xls文件如下(星号中的内容为你好.xls表格中的内容):

*****************
行和列 一列 二列 三列 四列
一行 123 456 789 12
二行 45 25 56 32
三行 121 26 56 89
***********

表中的数字都是以数值的形式(注意是数值)存在的。
输出结果错误
...全文
评论 9
收藏 已收藏
分享
返回顶部
tong_data
Java SE 62,621 成员 307,251 内容