GithubHelp home page GithubHelp logo

Comments (5)

rzymek avatar rzymek commented on August 12, 2024 1
Worksheet ws = wb.newWorksheet("Worksheet 1");
ws.formula(0, 0, "=HYPERLINK(\"https://github.com\")");

This code does create a clickable link in Excel 365 (v1901). It is not styled though:
image

xlsx generated with fastexcel: hyperlink.xlsx

from fastexcel.

rzymek avatar rzymek commented on August 12, 2024 1

For reference: Some technical info on current differences between fastexcel and Excel.

sheet.xml

Excel:

    <row r="1" spans="1:1" x14ac:dyDescent="0.25">
      <c r="A1" s="1" t="str">
        <f>HYPERLINK("https://wp.pl")</f>
        <v>https://wp.pl</v>
      </c>
    </row>

Fastexcel:

    <row r="1">
      <c r="A1" s="10">
        <f>=HYPERLINK("https://wp.pl")</f>
      </c>
    </row>

POI:

    <row r="2">
      <c r="B2" s="1" t="inlineStr">
        <is>
          <t>http://github.om/</t>
        </is>
      </c>

styles.xml

Excel:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:x16r2="http://schemas.microsoft.com/office/spreadsheetml/2015/02/main" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" mc:Ignorable="x14ac x16r2 xr">
  <fonts count="2" x14ac:knownFonts="1">
    <font>
      <sz val="11"/>
      <color theme="1"/>
      <name val="Calibri"/>
      <family val="2"/>
      <scheme val="minor"/>
    </font>
    <font>
      <u/>
      <sz val="11"/>
      <color theme="10"/>
      <name val="Calibri"/>
      <family val="2"/>
      <scheme val="minor"/>
    </font>
  </fonts>
  <fills count="2">
    <fill>
      <patternFill patternType="none"/>
    </fill>
    <fill>
      <patternFill patternType="gray125"/>
    </fill>
  </fills>
  <borders count="1">
    <border>
      <left/>
      <right/>
      <top/>
      <bottom/>
      <diagonal/>
    </border>
  </borders>
  <cellStyleXfs count="2">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0"/>
    <xf numFmtId="0" fontId="1" fillId="0" borderId="0" applyNumberFormat="0" applyFill="0" applyBorder="0" applyAlignment="0" applyProtection="0"/>
  </cellStyleXfs>
  <cellXfs count="2">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
    <xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="1"/>
  </cellXfs>
  <cellStyles count="2">
    <cellStyle name="Hyperlink" xfId="1" builtinId="8"/>
    <cellStyle name="Normal" xfId="0" builtinId="0"/>
  </cellStyles>
  <dxfs count="0"/>
  <tableStyles count="0" defaultTableStyle="TableStyleMedium2" defaultPivotStyle="PivotStyleLight16"/>
  <extLst>
    <ext xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" uri="{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}">
      <x14:slicerStyles defaultSlicerStyle="SlicerStyleLight1"/>
    </ext>
    <ext xmlns:x15="http://schemas.microsoft.com/office/spreadsheetml/2010/11/main" uri="{9260A510-F301-46a8-8635-F512D64BE5F5}">
      <x15:timelineStyles defaultTimelineStyle="TimeSlicerStyleLight1"/>
    </ext>
  </extLst>
</styleSheet>

Fastexcel:

<?xml version="1.0" encoding="UTF-8"?>
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <numFmts count="0"/>
  <fonts count="1">
    <font>
      <sz val="11.00"/>
      <color rgb="000000"/>
      <name val="Calibri"/>
    </font>
  </fonts>
  <fills count="2">
    <fill>
      <patternFill patternType="none"/>
    </fill>
    <fill>
      <patternFill patternType="gray125"/>
    </fill>
  </fills>
  <borders count="1">
    <border>
      <left/>
      <right/>
      <top/>
      <bottom/>
      <diagonal/>
    </border>
  </borders>
  <cellStyleXfs count="1">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0"/>
  </cellStyleXfs>
  <cellXfs count="1">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
  </cellXfs>
  <dxfs count="0"/>
</styleSheet>

POI:

<?xml version="1.0" encoding="UTF-8"?>
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  <numFmts count="0"/>
  <fonts count="2">
    <font>
      <sz val="11.0"/>
      <color indexed="8"/>
      <name val="Calibri"/>
      <family val="2"/>
      <scheme val="minor"/>
    </font>
    <font>
      <name val="Calibri"/>
      <sz val="11.0"/>
      <u val="single"/>
      <color indexed="12"/>
    </font>
  </fonts>
  <fills count="2">
    <fill>
      <patternFill patternType="none"/>
    </fill>
    <fill>
      <patternFill patternType="darkGray"/>
    </fill>
  </fills>
  <borders count="1">
    <border>
      <left/>
      <right/>
      <top/>
      <bottom/>
      <diagonal/>
    </border>
  </borders>
  <cellStyleXfs count="1">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0"/>
  </cellStyleXfs>
  <cellXfs count="2">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
    <xf numFmtId="0" fontId="1" fillId="0" borderId="0" xfId="0" applyFont="true"/>
  </cellXfs>
</styleSheet>

from fastexcel.

rzymek avatar rzymek commented on August 12, 2024

Apache POI sample:

try (SXSSFWorkbook wb = new SXSSFWorkbook()) {
    CreationHelper createHelper = wb.getCreationHelper();
    SXSSFSheet sheet = wb.createSheet();
    SXSSFCell cell = sheet.createRow(0).createCell(0);

    // Create link (unstyled)
    XSSFHyperlink link = (XSSFHyperlink)createHelper.createHyperlink(HyperlinkType.URL);
    link.setAddress("http://github.om/");
    cell.setCellValue(link.getAddress());
    cell.setHyperlink((XSSFHyperlink) link);

    // Set link style
    XSSFCellStyle hlinkstyle = (XSSFCellStyle) wb.createCellStyle();
    XSSFFont hlinkfont = (XSSFFont) wb.createFont();
    hlinkfont.setUnderline(XSSFFont.U_SINGLE);
    hlinkfont.setColor(HSSFColor.HSSFColorPredefined.BLUE.getIndex());
    hlinkstyle.setFont(hlinkfont);
    cell.setCellStyle(hlinkstyle);

    try (OutputStream out = new FileOutputStream("target/hpoi.xlsx")) {
        wb.write(out);
    }
}

from fastexcel.

ochedru avatar ochedru commented on August 12, 2024

I think @chrismaster is trying to create a link to a PDF file in e.g. the same directory as the workbook and in this case HYPERLINK does not work.

from fastexcel.

meiMingle avatar meiMingle commented on August 12, 2024

@ochedru This issue should be closed as #253

from fastexcel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.