读取出了excel后 把值拼成list
1 package Common; 2 3 import java.io.FileInputStream; 4 import java.io.InputStream; 5 import java.util.ArrayList; 6 import java.util.List; 7 8 import org.testng.annotations.Test; 9 10 import jxl.Cell; 11 import jxl.Sheet; 12 import jxl.Workbook; 13 14 public class excel { 15 16 public static List<List<String>> addexcel() throws Throwable{ 17 jxl.Workbook readwb = null; 18 InputStream instream = new FileInputStream("c:/萝卜丁.xls"); 19 readwb = Workbook.getWorkbook(instream); 20 Sheet readsheet = readwb.getSheet(0); 21 int rsColumns = readsheet.getColumns(); 22 int rsRows = readsheet.getRows(); 23 List<List<String>> list2 = new ArrayList<List<String>>(); 24 25 for(int column = 1;column < rsColumns;column ++) 26 { 27 ArrayList<String> list1=new ArrayList<String>(); 28 29 for(int row = 1;row < rsRows;row ++) 30 { 31 Cell cell = readsheet.getCell(column, row); 32 String content = cell.getContents(); 33 34 if(content == null|| content.isEmpty()) 35 { 36 continue; 37 } 38 39 if(content!=null){ 40 list1.add(content); 41 } 42 43 } 44 45 list2.add(list1); 46 } 47 System.out.println(list2); 48 return list2; 49 } 50 51 52 @Test 53 public void readexcel() throws Throwable { 54 55 addexcel(); 56 } 57 58 59 }