Skip to content

Commit

Permalink
making excel non URL based links adapt to a StringCell rather than Hy…
Browse files Browse the repository at this point in the history
…perLinkCell. Java throws a MalformedURLException otherwise
  • Loading branch information
tobyweston committed Apr 2, 2013
1 parent 6e7b46f commit dcb7c03
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
19 changes: 15 additions & 4 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/main/java/bad/robot/excel/matchers/CellType.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ public Cell adapt(org.apache.poi.ss.usermodel.Cell cell) {
String(CELL_TYPE_STRING) {
@Override
public Cell adapt(org.apache.poi.ss.usermodel.Cell cell) {
if (cell.getHyperlink() != null)
if (cell.getHyperlink() != null && containsUrl(cell.getHyperlink()))
return new HyperlinkCell(hyperlink(cell.getStringCellValue(), cell.getHyperlink().getAddress()));
return new StringCell(cell.getStringCellValue());
}

private boolean containsUrl(org.apache.poi.ss.usermodel.Hyperlink hyperlink) {
return hyperlink.getAddress().startsWith("http://") || hyperlink.getAddress().startsWith("file://");
}
},
Blank(CELL_TYPE_BLANK) {
@Override
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/bad/robot/excel/matchers/CellTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public void adaptHyperlinkCell() throws Exception {
assertThat(adaptPoi(getCellForCoordinate(coordinate(B, 5), workbook)), is(instanceOf(HyperlinkCell.class)));
}

@Test
public void adaptInternalLinkCell() throws IOException {
assertThat(adaptPoi(getCellForCoordinate(coordinate(B, 9), workbook)), is(instanceOf(StringCell.class)));
}

@Test
public void adaptBlankCell() throws IOException {
assertThat(adaptPoi(getCellForCoordinate(coordinate(C, 1), workbook)), is(instanceOf(BlankCell.class)));
Expand Down
Binary file modified src/test/resource/bad/robot/excel/cellTypes.xls
Binary file not shown.
Binary file not shown.

0 comments on commit dcb7c03

Please sign in to comment.