Reputation: 23
I am trying to read from webpage and write it to a excel sheet. Below is set of code works fine, but i am not able to figure out how to run this in a loop so that i can wright bulk data. As i have to write many value which i am reading from the table
FileOutputStream fo = new FileOutputStream("D:\\output.xls");
WritableWorkbook wb = Workbook.createWorkbook(fo);
WritableSheet ws = wb.createSheet("customsheet", 1);
This is the content which i am reading from webpage.
String m1 = (driver.findElement(By.xpath(".//*[@id='ctl00_ContentPlaceHolderBody_ucModelDataEntry1_lblPublishedFuelCostPerLoadEstimatedAllInCost']")).getText());
ws.getCell(m1);
Upvotes: 0
Views: 12300
Reputation: 23
Thanks for all your help But the below code worked for me
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();
Upvotes: 1
Reputation: 36304
First read the entire data you want to write.. Then start from a col say 0 , row number =1 - and then start writing data.. If you are storing the data in an arrayList, then
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
}
Upvotes: 0