0

filesexceptionI am using 2 excel sheets for reading and writing the data. Actually I want to send the results to a column. I am using MS Office 2010. I am struck up at the adding of Label. Please help. I got some error like extension/format. though I am using same 2010 office, while writing into a sheet, the previous data is removed, surprisingly!

String inFilePath = "D:\\PMC Automation\\Test Data with Queries.xls";
    FileInputStream inFile=new FileInputStream(inFilePath);
    Workbook W1=Workbook.getWorkbook(inFile);
    Sheet login_sheet=W1.getSheet("Login");
    Sheet countrysheet=W1.getSheet("Country");
    Sheet westsheet=W1.getSheet("WEST");

    String outFilePath = "D:\\PMC Automation\\Test Data with Queries
    with Results.xls";
    FileInputStream outFile=new FileInputStream(outFilePath);
    WritableWorkbook results=Workbook.createWorkbook(new File("D:\\PMC 
    Automation\\Test Data with Queries with Results.xls"));
    -----(statements)-----
   col++;
    for(int tui=0; tui<territorylist.size(); tui++)
    {
   allterritorylist.add
   (territorylist.get(tui).getAttribute("textContent"));
   if (westsheet.getCell(col, row).getContents().equalsIgnoreCase
   (territorylist.get(tui).getAttribute("textContent")))
            {
   System.out.println("\nTerritory " +westsheet.getCell
   (col, row).getContents()+ " existing in the Territory drop 
   down(UI)\n" );
   col++;
   //WritableSheet sheetwest=results.createSheet("mysheet", 0);
   WritableSheet sheetwest = results.getSheet("WEST");
   Label label= new Label(col, row, "PASS");
   sheetwest.addCell(label);
   col--;
   //Close Territory drop down
   driver.findElement(By.xpath("html/body/div[12]/div/ul/li[3]/a/span"))
   .click();
   Thread.sleep(300);
   }
  • 1
    Ok, now that you have posted the actual error, this question is a duplicate of [What is a NullPointerException, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – rmlan Sep 09 '16 at 12:59
  • 1
    Whatever your 'results' workbook is, it does not have a sheet called "WEST". Per the [POI Javadocs](https://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/Workbook.html#getSheet(java.lang.String)), getSheet will return null if a sheet does not exist. – rmlan Sep 09 '16 at 13:05
  • I have a copy of same sheet for which I am using to read the data. I am trying to add Results in another column. Please check the screen clip. While running the script the data inside is deleted or whatever, please check the file size – Suneel Kuppili Sep 09 '16 at 13:17
  • No. You create a workbook and then you never create sheets in that workbook. So I don't know what you think this code is doing, but it is not doing what you just described. – rmlan Sep 09 '16 at 13:28
  • I want to send the results to the WEST sheet itself in new column. My data is in 4 columns and note the results in 5th column. That's why I have not given .createworkbook, I just gave .getworkbook and tried also trying with createworkbook. But I am unable to.. Please correct me if I am wrong and provide the code. – Suneel Kuppili Sep 12 '16 at 05:21

0 Answers0