在java开发中,我需要把数据库里面的东西导出,生成一个excel文件,在导出的数据中,有一列是查 100
//设置超链接就可以了,可以参考下面的代码
//如何设置超链接
HSSFWorkbook wb = new HSSFWorkbook();
//超链接的单元格风格
//超链接默认的是蓝色底边框
HSSFCellStyle hlink_style = wb.createCellStyle();
HSSFFont hlink_font = wb.createFont();
hlink_font.setUnderline(HSSFFont.U_SINGLE);
hlink_font.setColor(HSSFColor.BLUE.index);
hlink_style.setFont(hlink_font);
HSSFCell cell;
HSSFSheet sheet = wb.createSheet("Hyperlinks");
//URL
cell = sheet.createRow(0).createCell((short)0);
cell.setCellValue("URL Link");
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
link.setAddress("");
cell.setHyperlink(link);
cell.setCellStyle(hlink_style);
//链接到当前路径的一个文件
cell = sheet.createRow(1).createCell((short)0);
cell.setCellValue("File Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);
link.setAddress("link1.xls");
cell.setHyperlink(link);
cell.setCellStyle(hlink_style);
//链接到e-mail
cell = sheet.createRow(2).createCell((short)0);
cell.setCellValue("Email Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_EMAIL);
//note, if subject contains white spaces, make sure they are url-encoded
link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
cell.setHyperlink(link);
cell.setCellStyle(hlink_style);
//链接到 workbook的某个地方
//创建一个目标Sheet和单元格
HSSFSheet sheet2 = wb.createSheet("Target Sheet");
sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");
cell = sheet.createRow(3).createCell((short)0);
cell.setCellValue("Worksheet Link");
link = new HSSFHyperlink(HSSFHyperlink.LINK_DOCUMENT);
link.setAddress("'Target Sheet'!A1");
cell.setHyperlink(link);
cell.setCellStyle(hlink_style);
FileOutputStream out = new FileOutputStream("c://hssf-links.xls");
wb.write(out);
out.close();
我现在是把函数输入进去,他只是一个字符串,必须我手动点一下他才变成一个超链接的样子
是用HSSFHyperlink这个方法像下面这样建的吗?excel哪个版本?
cell = sheet.createRow(0).createCell((short)0);
cell.setCellValue("URL Link");
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
link.setAddress("");
cell.setHyperlink(link);
cell.setCellStyle(hlink_style);
2016-05-16
广告 您可能关注的内容 |