0

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);
1
  • You'll need to store the values you get from scraping the web page somewhere. Consider using a Collection class. Commented Oct 16, 2013 at 14:26

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

Comments

0

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
    } 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.