读取出了excel后 把值拼成list

上一篇 / 下一篇  2017-03-23 14:18:46 / 个人分类:测试

package Common;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.testng.annotations.Test;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class excel {
public static List<List<String>> addexcel() throws Throwable{
jxl.Workbook readwb = null;
InputStream instream = new FileInputStream("c:/苹果.xls");
readwb = Workbook.getWorkbook(instream);
Sheet readsheet = readwb.getSheet(0);
int rsColumns = readsheet.getColumns();
int rsRows = readsheet.getRows();
List<List<String>> list2 = new ArrayList<List<String>>();

for(int column = 1;column < rsColumns;column ++)
{
ArrayList<String> list1=new ArrayList<String>();
for(int row = 1;row < rsRows;row ++)
{
Cell cell = readsheet.getCell(column, row);
String content = cell.getContents();

if(content == null|| content.isEmpty())
{
continue;
}
if(content!=null){
list1.add(content);
}
}

list2.add(list1);
}
System.out.println(list2);
return list2;
}

@Test
public void readexcel() throws Throwable {
addexcel();
}

}

TAG: Excel excel

 

评分:0

我来说两句

日历

« 2024-03-16  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

数据统计

  • 访问量: 23515
  • 日志数: 30
  • 建立时间: 2011-08-24
  • 更新时间: 2017-06-28

RSS订阅

Open Toolbar