0

我正在尝试从网页中读取并将其写入 Excel 表。下面是一组代码工作正常,但我无法弄清楚如何在循环中运行它,以便我可以编写批量数据。因为我必须写很多我从表中读取的值

FileOutputStream fo = new FileOutputStream("D:\\output.xls");
WritableWorkbook wb = Workbook.createWorkbook(fo);
WritableSheet ws = wb.createSheet("customsheet", 1);

这是我从网页上阅读的内容。

String m1 = (driver.findElement(By.xpath(".//*[@id='ctl00_ContentPlaceHolderBody_ucModelDataEntry1_lblPublishedFuelCostPerLoadEstimatedAllInCost']")).getText());
ws.getCell(m1);
4

2 回答 2

1

感谢您的所有帮助但以下代码对我有用

String m1 = (driver.findElement(By.xpath(".//*[@id='ctl00_ContentPlaceHolderBody_ucModelDataEntry1_lblPublishedFuelCostPerLoadEstimatedAlInCost']")).getText());
System.out.println(m1);
WritableWorkbook wb = Workbook.createWorkbook(new File("D:\\output_2.xls"));
writableSheet ws = wb.createSheet("customsheet",1);
{
Label label = new Label(0,0,m1);
ws.addCell(label);
}
wb.write();
wb.close();
于 2013-10-18T05:52:14.860 回答
0

首先读取您要写入的全部数据..然后从 col 开始说 0 ,行号 =1 - 然后开始写入数据..如果您将数据存储在 arrayList 中,那么

rowNo=1;
for(int colNo=0;colNo<arrList.size();colNo++)
   {
    Cell c = sheet0.getCell(colNo, rowNo);
  //    write data to your cell here... one by one - reading data from arraylist
    } 
于 2013-10-16T14:45:57.447 回答