You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2016/06/07 14:38:16 UTC

[Bug 59670] New: Sheet.getRow().getCell() gets the value from the next sheet along

https://bz.apache.org/bugzilla/show_bug.cgi?id=59670

            Bug ID: 59670
           Summary: Sheet.getRow().getCell() gets the value from the next
                    sheet along
           Product: POI
           Version: 3.14-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
          Assignee: dev@poi.apache.org
          Reporter: cbradford@lintottcs.co.uk

When using the HSSF library when I print the current sheet name it prints the
correct one. If I then get the cell value of a known cell in that sheet it will
return the value of the cell in the next sheet along.

How I get the sheet:
private static Sheet getSheet(Workbook wb, String sheetName){
        Sheet s = null;

        int numberOfSheets = workbook.getNumberOfSheets();

        for (int i = 0; i < numberOfSheets; i++) {

            s = wb.getSheet(sheetName);

            if( s.getSheetName().equals(sheetName)){
                return s;
            }
       }
       return s;
    }

How I get the cell value:
private static double getCellValue(Cell cell) {
        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC:
                return cell.getNumericCellValue();
            case Cell.CELL_TYPE_BLANK:
                return 0;
        }
      return 0;
}

double DOLabour = getCellValue(s.getRow(16).getCell(4));

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59670] Sheet.getRow().getCell() gets the value from the next sheet along

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59670

Nick Burch <ap...@gagravarr.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #3 from Nick Burch <ap...@gagravarr.org> ---
Won't the logic of your sheet selection loop mean that if the name doesn't
match, the last sheet will always be returned + used? Could that actually be
the cause of your issue?

If not, any chance you could turn your test code into a junit unit test that we
can use with your attached file to investigate more?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59670] Sheet.getRow().getCell() gets the value from the next sheet along

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59670

cbradford@lintottcs.co.uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

--- Comment #4 from cbradford@lintottcs.co.uk ---
I have stepped through the code and if I am looking for the "PP1" sheet the
function will return the "PP1" sheet and it will print this out using
s.getSheetName(). When I then get the cell value using:

How I get the cell value:
private static double getCellValue(Cell cell) {
        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC:
                return cell.getNumericCellValue();
            case Cell.CELL_TYPE_BLANK:
                return 0;
        }
      return 0;
}

double DOLabour = getCellValue(s.getRow(16).getCell(4))

It will actually return the value of the "Application" sheet not the "PP1"
sheet.

I have also noticed that when I loop through the sheets the first sheet is
called "Module1" not "PP1".

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59670] Sheet.getRow().getCell() gets the value from the next sheet along

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59670

cbradford@lintottcs.co.uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 OS|                            |All

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59670] Sheet.getRow().getCell() gets the value from the next sheet along

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59670

--- Comment #2 from cbradford@lintottcs.co.uk ---
Created attachment 33925
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=33925&action=edit
Workbook

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59670] Sheet.getRow().getCell() gets the value from the next sheet along

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59670

--- Comment #6 from Andreas Beeker <ki...@apache.org> ---
(In reply to cbradford from comment #5)
> Have you had any further developments with this bug?

I had a quick try on this and can only confirm the bug.
Althougn the bound name is correct, I suspect that the vba sheet is causing an
error with the sheet references ... but maybe someone else with a deeper
knowledge of hssf can jump in?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59670] Sheet.getRow().getCell() gets the value from the next sheet along

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59670

Andreas Beeker <ki...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #1 from Andreas Beeker <ki...@apache.org> ---
Please add also your example sheet

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59670] Sheet.getRow().getCell() gets the value from the next sheet along

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59670

cbradford@lintottcs.co.uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


[Bug 59670] Sheet.getRow().getCell() gets the value from the next sheet along

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59670

--- Comment #5 from cbradford@lintottcs.co.uk ---
Have you had any further developments with this bug?

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org