Domanda

I have a problem accessing data in cells from an Excel "*.xls" file. I need to access an Excel document. The document has an entry per line and all entries are in the first column. Here is a piece of the code

while(i < rowNumber){

            Cell cell = sheet.getCell(i, 0);
            temp = cell.getContents();
            regNo = "<html><body>" + "Reg No:     " + temp.substring(28, 38) + "<br/>";
            serialNo = "Serial No:  " + temp.substring(12, 27) + "<br/>";
            pin = "Pin:        " + temp.substring(0, 11) + "<br/>";
            date = "Date/Time:  " + date + "</body></html>";
            excelrow[i] = regNo + serialNo + pin + date;
            i++;
        }

I am sorry for the messy look of the code but it does what it has to. The problem I have is the first time cell.getContents() gets called, everything is fine but when its called again I get this error:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1.

I'm sure its something simple but can i get some help please. I am using the jxl api to access the excel files.

È stato utile?

Soluzione

The first parameter is column not row. I think you may have mixed the two up. See Javadocs.

Try:

Cell cell = sheet.getCell(0, i);

In any event, this is the line that is giving the error I am quite sure.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top