• 自动化测试随笔2


    读取出了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 }
  • 相关阅读:
    ABAP开发者上云的时候到了
    1074. 宇宙无敌加法器(20)
    1073. 多选题常见计分法(20)
    1072. 开学寄语(20)
    1071. 小赌怡情(15)
    1049. Counting Ones (30)
    1047. Student List for Course (25)
    1044. Shopping in Mars (25)
    1043. Is It a Binary Search Tree (25)
    1040. Longest Symmetric String (25)
  • 原文地址:https://www.cnblogs.com/by170628/p/7094842.html
Copyright © 2020-2023  润新知