public static void main(String[] args) throws Exception {
Workbook workbook=null;
Sheet sheet=null;
List list =new ArrayList();
InputStream input=new FileInputStream("E://tt.xls");
workbook =Workbook.getWorkbook(input);
sheet=workbook.getSheet(0);
for (int i = 0; i <sheet.getRows(); i++) {
String []str=new String[sheet.getColumns()];
for (int j = 0; j <sheet.getColumns(); j++) {
Cell cell=sheet.getCell(j,i);
str[j]=cell.getContents();
}
list.add(str);
}
for (int i = 0; i < list.size(); i++) {
String[]str=(String[]) list.get(i);
for (int j = 0; j < str.length; j++) {
System.out.println(str[j]);
}
}
}
这是list的方法,求一个map的跟遍历输出谢谢。
首先感谢,劳驾你再帮帮忙,map中key的值是标题,比如标题是姓名,年龄,住址。数据是张三,12,海南。
用java读取excle文件用list,map接收,list实现了,map怎么也不行,急死了。
答案:1 悬赏:0 手机版
解决时间 2021-02-11 15:53
- 提问者网友:你挡着我发光了
- 2021-02-10 21:38
最佳答案
- 五星知识达人网友:行路难
- 2021-02-10 21:59
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*;
import jxl.*;
public class Test3{
public static void main(String[] args) throws Exception {
Workbook workbook=null;
Sheet sheet=null;
TreeMap<Integer,String[]> map = new TreeMap<Integer,String[]>();
InputStream input=new FileInputStream("D://tt.xls");
workbook =Workbook.getWorkbook(input);
sheet=workbook.getSheet(0);
for (int i = 0; i <sheet.getRows(); i++) {
String []str=new String[sheet.getColumns()];
for (int j = 0; j <sheet.getColumns(); j++) {
Cell cell=sheet.getCell(j,i);
str[j]=cell.getContents();
}
map.put(i+1, str);
}
for (int i = 0; i < map.size(); i++) {
for (int j = 0; j < map.get(i+1).length; j++) {
System.out.print(map.get(i+1)[j]+" ");
}
System.out.println();
}
}
}
你是想要这种效果吗?
import java.io.InputStream;
import java.util.*;
import jxl.*;
public class Test3{
public static void main(String[] args) throws Exception {
Workbook workbook=null;
Sheet sheet=null;
TreeMap<Integer,String[]> map = new TreeMap<Integer,String[]>();
InputStream input=new FileInputStream("D://tt.xls");
workbook =Workbook.getWorkbook(input);
sheet=workbook.getSheet(0);
for (int i = 0; i <sheet.getRows(); i++) {
String []str=new String[sheet.getColumns()];
for (int j = 0; j <sheet.getColumns(); j++) {
Cell cell=sheet.getCell(j,i);
str[j]=cell.getContents();
}
map.put(i+1, str);
}
for (int i = 0; i < map.size(); i++) {
for (int j = 0; j < map.get(i+1).length; j++) {
System.out.print(map.get(i+1)[j]+" ");
}
System.out.println();
}
}
}
你是想要这种效果吗?
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯