public void testSetHyperLink() {
XSSFWorkbook workbook = new XSSFWorkbook();
try {
FileOutputStream out = new FileOutputStream("d:\\testSetHyperLink.xlsx");
XSSFSheet sheet = workbook.createSheet("1");
XSSFCellStyle style = workbook.createCellStyle();
XSSFFont font = workbook.createFont();
font.setUnderline(XSSFFont.U_DOUBLE);
font.setColor(IndexedColors.RED.getIndex());
style.setFont(font);
CreationHelper createHelper = workbook.getCreationHelper();
XSSFCellStyle cellStyle = workbook.createCellStyle();
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
cell.setCellValue("杨晨辉的单词表.xlsx");
XSSFFont font1 = workbook.createFont();
font1.setColor(HSSFColor.GREEN.index);
cellStyle.setFont(font1);
cell.setCellStyle(cellStyle);
Hyperlink hyperlink = createHelper.createHyperlink(Hyperlink.LINK_FILE);
hyperlink.setAddress("C://Users//Administrator//Desktop//杨晨辉的单词表.xlsx");
cell.setHyperlink(hyperlink);
workbook.write(out);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
网友评论