0

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

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

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

1

Not tested on my end right now but sure it will work. Please change according your values

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);

and at the end you need to add style to the cell

cell.setCellStyle(hlink_style);
于 2013-10-30T09:48:47.517 回答