Reading Category and Items From excel

99 views Asked by At

My Excel File

I wanna read category from excel file i cant read it by row number because items may vary. I am using jxl. I can take each cell type but Im getting Type Label for every cell

try {
        Workbook workbook = Workbook.getWorkbook(new File(
                "path to excel file"));
        Sheet sheet = workbook.getSheet(0);
        int colCount = sheet.getRows();
        for (int i = 0; i < colCount; i++) {
            Cell cell = sheet.getCell(0, i);
            System.out.println(cell.getType() + " " + cell.getContents());
        }
    } catch (BiffException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

I need to take Category names separately.

1

There are 1 answers

2
laune On

As an alternative, read column Quantity.

The first row contains a "Category" - retrieve and save (or whatever). Retrieve the numeric value from the cell, call it sum. Then, continue reading thw cells below. Retrieve the numeric value and subtract from sum. If sum is reduced to 0, increment the row, and repeat, unless you exceed the number of rows.