Re: Reading data from Excel sheet and storing the values in variables

2,069 views
Skip to first unread message
Message has been deleted

Shawn McCarthy

unread,
Dec 14, 2013, 3:05:16 AM12/14/13
to seleniu...@googlegroups.com
Not related to selenium.

On Friday, December 13, 2013 6:31:05 AM UTC-7, haseeb akhter wrote:

I have an excell sheet named "Test File.xlsx". I want to get the values in the cells of the sheet and store every individual values in different randomly generated variables. And later on compare the value in those variables on different pages of my site with the values already stored in there.

The data is numeric in some columns and string in other columns. e.g. first column has alphanumeric data , the 2nd column has int data and the third has string data. 

I have read the following code but it seems only to store data in array. kindly help as i am new to selenium. I am using Java, selenium, win 8, IE10.

`import java.io.IOException;
 import jxl.Cell;
 import jxl.Sheet;
 import jxl.Workbook;
import jxl.read.biff.BiffException;

public class NewExcel 
{

private String inputFile;
String[][] data = null;
public void setInputFile(String inputFile) 
{
    this.inputFile = inputFile;
}

public String[][] read() throws IOException  
{
    File inputWorkbook = new File(inputFile);
    Workbook w;

    try 
    {
        w = Workbook.getWorkbook(inputWorkbook);
         data = new String[sheet.getColumns()][sheet.getRows()];
        // Loop over first 10 column and lines
   //     System.out.println(sheet.getColumns() +  " " +sheet.getRows());
        for (int j = 0; j <sheet.getColumns(); j++) 
        {
            for (int i = 0; i < sheet.getRows(); i++) 
            {
                Cell cell = sheet.getCell(j, i);
                data[j][i] = cell.getContents();
  //  System.out.println(cell.getContents());
            }
        }

     /*   for (int j = 0; j < data.length; j++) 
        {
            for (int i = 0; i <data[j].length; i++) 
            {

                System.out.println(data[j][i]);
            }
        } */

    } 
    catch (BiffException e) 
    {
        e.printStackTrace();
    }
return data;
}


}
 public static void main(String[] args) throws IOException 
{
    NewExcel test = new NewExcel();
    test.setInputFile("D:\\Haseeb\\Test file.xlsx");
    test.read();
}

}`
Message has been deleted

haseeb akhter

unread,
Dec 16, 2013, 12:05:30 AM12/16/13
to seleniu...@googlegroups.com
but i  am using it selenium, can you please help with the java code??

Krishnan Mahadevan

unread,
Dec 16, 2013, 1:12:27 AM12/16/13
to Selenium Users
Just because your code had selenium classes reference in it doesnt mean that this question is related to Selenium.
WebDriver/Selenium doesnt deal with excel sheets.

I would suggest that you please try googling for this [ responding back with, I searched a lot and didnt find so please help.. is not going to help here.. :) ]

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/


On Mon, Dec 16, 2013 at 10:35 AM, haseeb akhter <hasee...@gmail.com> wrote:
but i  am using it selenium, can you please help with the java code??

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/ff136819-d963-4e99-ae3a-e67f9c5108cb%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages