admin 管理员组文章数量: 1184232
2024年3月19日发(作者:web前端工程师等级)
下面是例子:
import ;
import putStream;
import ption;
import tream;
import ist;
import ;
import ;
import ;
import ok;
import ception;
/**
* 读取excel公共方法
*
*
*/
public class ExcelReader {
/**
*
* @param excelFile 读取文件对象
* @param rowNum 从第几行开始读,如果有一行表头则从第二行开始读
* @return
* @throws BiffException
* @throws IOException
*/
public static List
BiffException,
IOException {
// 创建一个list 用来存储读取的内容
List
Workbook rwb = null;
Cell cell = null;
// 创建输入流
InputStream stream = new FileInputStream(excelFile);
// 获取Excel文件对象
rwb = kbook(stream);
// 获取文件的指定工作表 默认的第一个
Sheet sheet = et(0);
// 行数(表头的目录不需要,从1开始)
for (int i = rowNum-1; i < s(); i++) {
// 创建一个数组 用来存储每一列的值
String[] str = new String[umns()];
// 列数
for (int j = 0; j < umns(); j++) {
// 获取第i行,第j列的值
cell = l(j, i);
str[j] = tents();
}
// 把刚获取的列存入list
(str);
}
// 返回值集合
return list;
}
public static void main(String[] args) {
String excelFileName = "";
try {
List
for (int i = 0; i < (); i++) {
String[] str = (String[])(i);
for (int j = 0; j < ; j++) {
n(str[j]);
}
}
} catch (BiffException e) {
tackTrace();
} catch (IOException e) {
tackTrace();
}
}
}
以上list中值为所读取之后存储的集合。
版权声明:本文标题:java如何读取Excel中的数据 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1710790245a573257.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论