From 7593d5484d1f7d69dc65385b9d6b91c9b0f39a22 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 25 Dec 2019 22:24:58 +0100 Subject: [PATCH] Add Hyperlink to cell in Excel importer, with fallback to String, for #2213 --- .../com/google/refine/exporters/XlsExporter.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/main/src/com/google/refine/exporters/XlsExporter.java b/main/src/com/google/refine/exporters/XlsExporter.java index 48100b0ae..461cc9f28 100644 --- a/main/src/com/google/refine/exporters/XlsExporter.java +++ b/main/src/com/google/refine/exporters/XlsExporter.java @@ -39,7 +39,7 @@ import java.time.OffsetDateTime; import java.util.List; import java.util.Properties; -import org.apache.poi.common.usermodel.Hyperlink; +import org.apache.poi.ss.usermodel.Hyperlink; import org.apache.poi.common.usermodel.HyperlinkType; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; @@ -127,9 +127,15 @@ public class XlsExporter implements StreamExporter { } if (cellData.link != null) { - Hyperlink hl = wb.getCreationHelper().createHyperlink(HyperlinkType.URL); - hl.setLabel(cellData.text); - hl.setAddress(cellData.link); + try { + Hyperlink hl = wb.getCreationHelper().createHyperlink(HyperlinkType.URL); + hl.setLabel(cellData.text); + hl.setAddress(cellData.link); + c.setHyperlink(hl); + } catch(IllegalArgumentException e) { + // If we failed to create the hyperlink and add it to the cell, + // we just use the string value as fallback + } } } }