Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java =================================================================== --- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java (revisione 187238) +++ src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java (copia locale) @@ -22,6 +22,7 @@ import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackageRelationship; import org.apache.poi.ss.usermodel.Hyperlink; +import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellReference; import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHyperlink; @@ -224,8 +225,12 @@ _ctHyperlink.setRef(ref); } - private CellReference buildCellReference() { - return new CellReference(_ctHyperlink.getRef()); + private CellRangeAddress buildCellRangeAddress() { + String cellRef = _ctHyperlink.getRef(); + if (cellRef == null) { + return null; + } + return CellRangeAddress.valueOf(cellRef); } @@ -235,7 +240,11 @@ * @return the 0-based column of the first cell that contains the hyperlink */ public int getFirstColumn() { - return buildCellReference().getCol(); + CellRangeAddress cellRange = buildCellRangeAddress(); + if (cellRange == null) { + return 0; + } + return cellRange.getFirstColumn(); } @@ -245,7 +254,11 @@ * @return the 0-based column of the last cell that contains the hyperlink */ public int getLastColumn() { - return buildCellReference().getCol(); + CellRangeAddress cellRange = buildCellRangeAddress(); + if (cellRange == null) { + return 0; + } + return cellRange.getLastColumn(); } /** @@ -254,7 +267,11 @@ * @return the 0-based row of the cell that contains the hyperlink */ public int getFirstRow() { - return buildCellReference().getRow(); + CellRangeAddress cellRange = buildCellRangeAddress(); + if (cellRange == null) { + return 0; + } + return cellRange.getFirstRow(); } @@ -264,7 +281,11 @@ * @return the 0-based row of the last cell that contains the hyperlink */ public int getLastRow() { - return buildCellReference().getRow(); + CellRangeAddress cellRange = buildCellRangeAddress(); + if (cellRange == null) { + return 0; + } + return cellRange.getLastRow(); } /** @@ -273,11 +294,17 @@ * @param col the 0-based column of the first cell that contains the hyperlink */ public void setFirstColumn(int col) { - _ctHyperlink.setRef( - new CellReference( - getFirstRow(), col - ).formatAsString() - ); + CellRangeAddress cellRange = buildCellRangeAddress(); + if (cellRange == null) { + _ctHyperlink.setRef( + new CellReference( + getFirstRow(), col + ).formatAsString() + ); + } else { + cellRange.setFirstColumn(col); + _ctHyperlink.setRef(cellRange.formatAsString()); + } } /** @@ -286,7 +313,13 @@ * @param col the 0-based column of the last cell that contains the hyperlink */ public void setLastColumn(int col) { - setFirstColumn(col); + CellRangeAddress cellRange = buildCellRangeAddress(); + if (cellRange == null) { + setFirstColumn(col); + } else { + cellRange.setLastColumn(col); + _ctHyperlink.setRef(cellRange.formatAsString()); + } } /** @@ -295,11 +328,17 @@ * @param row the 0-based row of the first cell that contains the hyperlink */ public void setFirstRow(int row) { - _ctHyperlink.setRef( - new CellReference( - row, getFirstColumn() - ).formatAsString() - ); + CellRangeAddress cellRange = buildCellRangeAddress(); + if (cellRange == null) { + _ctHyperlink.setRef( + new CellReference( + row, getFirstColumn() + ).formatAsString() + ); + } else { + cellRange.setFirstRow(row); + _ctHyperlink.setRef(cellRange.formatAsString()); + } } /** @@ -308,7 +347,13 @@ * @param row the 0-based row of the last cell that contains the hyperlink */ public void setLastRow(int row) { - setFirstRow(row); + CellRangeAddress cellRange = buildCellRangeAddress(); + if (cellRange == null) { + setFirstRow(row); + } else { + cellRange.setLastRow(row); + _ctHyperlink.setRef(cellRange.formatAsString()); + } } /**