Reading Excel with JXL, number of cells per row, varying between rows

I tried to find a solution already, but nothing worked, which corresponds to my problem. I use JXL to read an Excel spreadsheet and convert each row to the specified object. Each cell inside the row corresponds to the property of the object that I create. My table has 41 columns and after reading 375 rows the number of cells in a row changes from 41 to 32. I can’t understand why.

Here is the code where I iterate over the rows and retrieve the cells:

  w = Workbook.getWorkbook(inputWorkbook);
  // Get the first sheet
  Sheet sheet = w.getSheet(0);
  // Loop over first 10 column and lines

  for (int row=1; row < sheet.getRows();row++)
  {
      EventData event = new EventData();
      // we skip first row bc that should be header info
      //now iterate through columns in row
      try
      {
          Cell[] cell = sheet.getRow(row);

          event.Name = cell[0].getContents();
          event.Location = cell[1].getContents();

The rest of the code continues to capture the contents of each cell and assigns them accordingly. But when you try to access cell [32] on line 376, I get an exception outside.

+5
source share
1 answer

, , [32] , , , [32] ( ) ? jxl, , ,

+2

All Articles