【问题标题】:Failure load cell with hyperlink in Poi?Poi中带有超链接的称重传感器失效?
【发布时间】:2013-11-09 03:09:52
【问题描述】:

我一直在尝试将超链接应用于一列链接,乍一看它不起作用,但是当我双击单元格时,在该单元格中激活了新的超链接,我可以解决这个问题,我详细说明我的代码。

HSSFCellStyle styleCellWhite = (HSSFCellStyle) wb.createCellStyle();
HSSFFont fontCellWhite = (HSSFFont) wb.createFont();
fontCellWhite.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
HSSFColor lightWhite = setColor(wb,(byte) 255, (byte) 255,(byte) 255);
styleCellWhite.setFillForegroundColor(lightWhite.getIndex());
styleCellWhite.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
styleCellWhite.setFont(fontCell);
styleCellWhite.setBorderBottom((short) 1);
styleCellWhite.setBorderLeft((short) 1);            
styleCellWhite.setBorderRight((short) 1);
styleCellWhite.setBorderTop((short) 1);

int i=8;
int k = 1;
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
for(Sistema sistema : sists) {   
    HSSFRow rows  = sheet.createRow((short) i+1);
    b1 = rows.createCell((short) 1);
    b1.setCellValue(k);             
    b1.setCellStyle(k % 2 == 0 ? styleCell : styleCellWhite);                           
    f1 = rows.createCell((short) 2);
    link.setAddress(sistema.getDireccionUrl());
    f1.setCellValue(sistema.getDireccionUrl());    
    f1.setHyperlink(link);
    f1.setCellStyle(k % 2 == 0 ? styleCell : styleCellWhite);                   
    g1 = rows.createCell((short) 3);
    g1.setCellValue(sistema.getNombrePropietario());
    g1.setCellStyle(k % 2 == 0 ? styleCell : styleCellWhite);               
    h1 = rows.createCell((short) 4);
    h1.setCellValue(sistema.getEstado().equals(Constante.EST_ACTIVO) ? "ACTIVO" : "INACTIVO");
    h1.setCellStyle(k % 2 == 0 ? styleCell : styleCellWhite);
    i++;
    k++;
}

【问题讨论】:

  • 如果是这样的话,如何修复这个缺陷??

标签: java excel hyperlink apache-poi


【解决方案1】:

我现在还没有经过测试,但肯定会奏效。请根据你的价值观改变

CellStyle hlink_style = wb.createCellStyle();
Font hlink_font = wb.createFont();
hlink_font.setUnderline(Font.U_SINGLE);
hlink_font.setColor(IndexedColors.BLUE.getIndex());
hlink_style.setFont(hlink_font);

最后你需要为单元格添加样式

cell.setCellStyle(hlink_style);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 2017-04-29
    相关资源
    最近更新 更多