0
import java.io.*;
import java.util.*;

import jxl.*;
import jxl.read.biff.BiffException;

public class ExcelIO {

    // A factory method which takes in an excel file and reads in the contents.

  public static void readData(String args[]) throws BiffException, IOException{

      Workbook wb=  Workbook.getWorkbook(new File("E:\\Java\\java ramesh trainer notes\\Selenium\\ReadData.xlsx"));
      Sheet sheet= wb.getSheet(0);

      String[][] col;
      //get username and password from excel
      for(int i=0;i<sheet.getRows();i++){
          for(int j=0; j<sheet.getColumns();j++){
             Cell cell= sheet.getCell(i+1,j+1);
             String str= cell.getContents();

             col= str.toString();
          }
      }


  }
}
CubeJockey
  • 2,209
  • 8
  • 24
  • 31

2 Answers2

0

When you iterate like that, you need to set the value of col at each index to the string, not col itself. col is a 2-D array, not a String. As such, you need to change the string at col[i][j] to str.toString(). On a related topic, you could set each column of col to a 1-D array, as in col[i] = new String[length], because col[i] is a String array, etc.

Also, it's worth noting that you have to initialize col to have a height and width, as arrays cannot change size or add cells.

17slim
  • 1,233
  • 1
  • 16
  • 21
0

You will need to initialize your array as well. col = new String[x][y]

If you need to find how big to make your array you can either run a preliminary loop through and record the size or resize the array if it is filled up.

Also, as others have pointed out you will need. col[i][j] = str;

The getContents method of jxl returns a string so the toString() method should be unnecessary.

Generic Guy
  • 159
  • 8