title: How to Use Apache POI to create excel hyper link that links to long url
body: <p>Excel is having a <a href="https://www.mrexcel.com/forum/excel-questions/539414-how-do-i-do-hyperlink-exceeds-255-characters.html" rel="nofollow noreferrer">hyper link size limit of 255</a>.</p>
  
  <p>Now I'm using Apache POI to programmatically fill in a excel, but with a s3 pre-signed url that is much longer than 255 characters, 1350+ in length.</p>
  
  <p>And when I click the hyper link created in excel, it's showing alert as follows: "An unexpected error has occurred."</p>
  
  <p>Here's my corresponding code:</p>
  
  <pre><code>import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  import org.apache.poi.common.usermodel.HyperlinkType;
  import org.apache.poi.ss.usermodel.Cell;
  import org.apache.poi.ss.usermodel.CellStyle;
  import org.apache.poi.ss.usermodel.CreationHelper;
  import org.apache.poi.ss.usermodel.FillPatternType;
  import org.apache.poi.ss.usermodel.IndexedColors;
  import org.apache.poi.ss.usermodel.Row;
  import org.apache.poi.xssf.usermodel.XSSFCellStyle;
  import org.apache.poi.xssf.usermodel.XSSFFont;
  import org.apache.poi.xssf.usermodel.XSSFHyperlink;
  import org.apache.poi.xssf.usermodel.XSSFSheet;
  import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  
    public void generateExcel(List&lt;FunctionalTestCaseResult&gt; data) {
  
        XSSFWorkbook workbook = new XSSFWorkbook();
        CreationHelper createHelper = workbook.getCreationHelper();
        XSSFSheet sheet = workbook.createSheet("Sheet1");
  
        int rowNum = 0;
        Row row = sheet.createRow(rowNum++);
        int cellNum = 0;
        CellStyle captionStyle = workbook.createCellStyle();
        captionStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
        captionStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
  
        //create hyper link style
        XSSFCellStyle hlinkstyle = workbook.createCellStyle();
        XSSFFont hlinkfont = workbook.createFont();
        hlinkfont.setUnderline(XSSFFont.U_SINGLE);
        hlinkfont.setColor(IndexedColors.BLUE.index);
        hlinkstyle.setFont(hlinkfont);
  
        Cell cell = row.createCell(cellNum++);
  
        XSSFHyperlink link = (XSSFHyperlink)createHelper.createHyperlink(HyperlinkType.URL);
        link.setAddress(recordingS3Url);
        cell.setHyperlink(link);
        cell.setCellValue("Recording url");
        cell.setCellStyle(hlinkstyle);
  
    }
  </code></pre>