private static String getHyperlinkHtml(
     String label,
     SHyperlink link,
     SSheet sheet,
     SCell cell,
     SCellStyle cellStyle,
     FormatResult ft,
     SCellStyle tbStyle) { // ZSS-1018
   String addr =
       escapeText(
           link.getAddress() == null ? "" : link.getAddress(),
           false,
           false); // TODO escape something?
   if (label == null) {
     label = escapeText(link.getLabel(), false, false);
   }
   if (label == null) {
     label = escapeText(addr, false, false);
   }
   final StringBuffer sb = new StringBuffer();
   // ZSS-233, don't use href directly to avoid direct click on spreadsheet at the beginning.
   sb.append("<a zs.t=\"SHyperlink\" z.t=\"")
       .append(link.getType().getValue())
       .append("\" href=\"javascript:\" z.href=\"")
       .append(addr)
       .append("\" style=\"") // ZSS-1018
       .append(getFontHtmlStyle(sheet, cell, cellStyle, ft, tbStyle)) // ZSS-1018
       .append("\">")
       .append(label == null ? "" : label)
       .append("</a>");
   return sb.toString();
 }
Example #2
0
  @Test
  public void testSetHyperlink() {
    SBook book = SBooks.createBook("book1");
    SSheet sheet1 = book.createSheet("Sheet1");
    SRange range = SRanges.range(sheet1, "A1:B2");
    range.setHyperlink(HyperlinkType.URL, "http://www.google.com", "Google");

    SHyperlink link = range.getHyperlink();
    Assert.assertEquals(HyperlinkType.URL, link.getType());
    Assert.assertEquals("http://www.google.com", link.getAddress());
    Assert.assertEquals("Google", link.getLabel());

    Assert.assertEquals("Google", sheet1.getCell("A1").getStringValue());

    link = SRanges.range(sheet1, "B2").getHyperlink();
    Assert.assertEquals(HyperlinkType.URL, link.getType());
    Assert.assertEquals("http://www.google.com", link.getAddress());
    Assert.assertEquals("Google", link.getLabel());
    Assert.assertEquals("Google", sheet1.getCell("B2").getStringValue());
  }