Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何通过selenium在excel中编写数组对象内容 int col=driver.findElements(By.xpath(“//table[@id=\“transactionListData\”]/thead/tr/th”).size(); int row=driver.findElements(By.xpath(“//table[@id=\“transactionListData\”]/tbody/tr”).size(); //ArrayList mydata=新的ArrayList(); Object[]ob=新对象[行][col]; 对于(int i=1;i_Java_Selenium - Fatal编程技术网

Java 如何通过selenium在excel中编写数组对象内容 int col=driver.findElements(By.xpath(“//table[@id=\“transactionListData\”]/thead/tr/th”).size(); int row=driver.findElements(By.xpath(“//table[@id=\“transactionListData\”]/tbody/tr”).size(); //ArrayList mydata=新的ArrayList(); Object[]ob=新对象[行][col]; 对于(int i=1;i

Java 如何通过selenium在excel中编写数组对象内容 int col=driver.findElements(By.xpath(“//table[@id=\“transactionListData\”]/thead/tr/th”).size(); int row=driver.findElements(By.xpath(“//table[@id=\“transactionListData\”]/tbody/tr”).size(); //ArrayList mydata=新的ArrayList(); Object[]ob=新对象[行][col]; 对于(int i=1;i,java,selenium,Java,Selenium,上述问题的答案是: public static String writeIntoExcel(Object ob, int rowi,int colj ) throws IOException { int rowcount = rowi; int colcount = colj; Object oa[][] = new Object[rowcount][colcount]; oa = (Object[][]) ob; XSSFWorkbook work

上述问题的答案是:

public static String writeIntoExcel(Object ob, int rowi,int colj ) throws IOException
{
    int rowcount =  rowi;
    int colcount = colj;
    Object oa[][]  = new Object[rowcount][colcount];
    oa =  (Object[][]) ob;
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("Transacton History");

    for (int i=1; i<=rowcount ; i++)
    {
        for (int j=1; j<=colcount ; j++)
        {
            String val = (String) oa[i][j];
            Row row = sheet.createRow(i);
            row.createCell(colj).setCellValue(val);
        }
    }
    FileOutputStream fileOut = new FileOutputStream("\"\\\\btfin.com\\filesrv\\User\\Offshore\\SG1\\L097117\\user\\My Documents\\workbook.xlsx");
    workbook.write(fileOut);
    fileOut.close();

    return "Data is written";
}
Object[][]ob=新对象[行][col];

对于(int i=1;i您得到的错误是什么?将该信息和任何其他相关信息添加到您的问题中。您应该花一些时间阅读有关此问题的教程。您这样做的方式效率不高且令人困惑。为什么要传递
对象而不是字符串数组之类的特定数据类型?如果传入arr是的,您不需要传入行和列,因为您可以从数组维度本身获取。不要返回“数据已写入”之类的内容,而是返回布尔值…
true
(如果成功),或
false
(如果未成功)或类似的内容。
public static String writeIntoExcel(Object ob, int rowi,int colj ) throws IOException
{
    int rowcount =  rowi;
    int colcount = colj;
    Object oa[][]  = new Object[rowcount][colcount];
    oa =  (Object[][]) ob;
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("Transacton History");

    for (int i=1; i<=rowcount ; i++)
    {
        for (int j=1; j<=colcount ; j++)
        {
            String val = (String) oa[i][j];
            Row row = sheet.createRow(i);
            row.createCell(colj).setCellValue(val);
        }
    }
    FileOutputStream fileOut = new FileOutputStream("\"\\\\btfin.com\\filesrv\\User\\Offshore\\SG1\\L097117\\user\\My Documents\\workbook.xlsx");
    workbook.write(fileOut);
    fileOut.close();

    return "Data is written";
}
    Object [][] ob = new Object[row][col];
    for( int i=1; i<=row; i++)
    {
        for (int j=1; j<=col; j++)
        {
            String text =driver.findElement(By.xpath("//*[@id='transactionListData']/tbody/tr["+i+"]/td["+j+"]")).getText();
            //System.out.println("text " +text);
            ob[i-1][j-1] = text;                
        }
    }
public static String writeIntoExcel(Object[][] sob ) throws IOException
{

    //String oa[][]  = sob;
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("Transacton History");
    Object cellvalue = null;                         
    for (int i=0; i<=sob.length ; i++)
    {
        Row row = sheet.createRow(i + 1);
        for (int j=0; j<=sob[i].length ; j++)
        {
            Cell cell=row.createCell(j+1);
            cellvalue = sob[i][j];
            if (cellvalue instanceof String)
                cell.setCellValue((String)(cellvalue));
            else if (cellvalue instanceof Integer)
                cell.setCellValue((Integer)cellvalue);

            cell.setCellValue((String)cellvalue);
        }
    }
    FileOutputStream fileOut = new FileOutputStream("");
    workbook.write(fileOut);
    fileOut.close();
    workbook.close();

    return "Data is written";