在Poi中带有超链接的故障称重传感器?

时间:2013-10-29 19:09:57

标签: java excel hyperlink apache-poi

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

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++;
}

enter image description here

enter image description here

1 个答案:

答案 0 :(得分: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);