问: 20 在java开发中,我需要把数据库里面的东西导出,生成一个excel文件,在导出的数据
答案:3 悬赏:0 手机版
解决时间 2021-01-03 23:00
- 提问者网友:别再叽里呱啦
- 2021-01-03 07:57
问: 20 在java开发中,我需要把数据库里面的东西导出,生成一个excel文件,在导出的数据中,有一列是查看照片地址,点击会弹出网页打开图片,可是我如果把地址直接弄出来,就只是一个字符串,该怎么在动态生成excel文件的时候去设置excel的函数,实现这个功能
最佳答案
- 五星知识达人网友:掌灯师
- 2021-01-10 02:56
我不知道你用什么导出excel,我用过poi,里面有Hyperlink 函数可以实现。
cell = row.createCell(colNumber)。
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula("HYPERLINK(\"" + "www.google.ca"+" target="_blank">http://www.google.ca"+ "\",\"" + "Google Canada"+ "\")");
或cell.setCellFormula("HYPERLINK(\"[workbook.xls]'sheet2'!A1\",\"homepage\")");
cell = row.createCell(colNumber)。
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula("HYPERLINK(\"" + "www.google.ca"+" target="_blank">http://www.google.ca"+ "\",\"" + "Google Canada"+ "\")");
或cell.setCellFormula("HYPERLINK(\"[workbook.xls]'sheet2'!A1\",\"homepage\")");
全部回答
- 1楼网友:渡鹤影
- 2021-01-10 05:07
这个我做奖金,考勤系统的时候经常用到,是一个方法,希望能帮到你。
用的apache poi:
private byte[] mainprocessbonuslisttoreport(list bonuses){
hssfworkbook hssfworkbook = new hssfworkbook();
hssfsheet hssfsheet =hssfworkbook.createsheet("总奖金报表单");
hssfsheet.addmergedregion(new cellrangeaddress(0, 0, 0, 12));
hssfrow hssfrow = hssfsheet.createrow(0);
hssfcell hssfcell=hssfrow.createcell(0);
hssfcell.setcellvalue("派单业务考核记录");
hssfrow = hssfsheet.createrow(1);
string[] titles = {"序号","工号","话务员姓名","规范奖考核","业务奖金","话务奖金","服务质量奖金","星级系数","组长津贴","总奖金","增资奖金","英语翻译","实发总奖金"};
for (int i = 0; i < titles.length; i++) {
hssfcell = hssfrow.createcell(i);
hssfcell.setcellvalue(titles[i]);
}
int rowindex=2;
for (bonus bonus : bonuses) {
hssfrow = hssfsheet.createrow(rowindex);
hssfcell = hssfrow.createcell(0);
hssfcell.setcellvalue(rowindex-1);
hssfcell = hssfrow.createcell(1);
hssfcell.setcellvalue(bonus.getworknumber());
hssfcell = hssfrow.createcell(2);
hssfcell.setcellvalue(bonus.getname());
hssfcell = hssfrow.createcell(3);
hssfcell.setcellvalue(bonus.getstandardperformance());
hssfcell = hssfrow.createcell(4);
hssfcell.setcellvalue(bonus.getbusinessbonus());
hssfcell = hssfrow.createcell(5);
hssfcell.setcellvalue(bonus.getcallbonus());
hssfcell = hssfrow.createcell(6);
hssfcell.setcellvalue(bonus.getservicequalitybonus());
hssfcell = hssfrow.createcell(7);
hssfcell.setcellvalue(bonus.getstarcoefficient());
hssfcell = hssfrow.createcell(8);
hssfcell.setcellvalue(bonus.getgroupleaderallowance());
hssfcell = hssfrow.createcell(9);
hssfcell.setcellvalue(bonus.gettotalbonus());
hssfcell = hssfrow.createcell(10);
hssfcell.setcellvalue(bonus.getadditionalbonus());
hssfcell = hssfrow.createcell(11);
hssfcell.setcellvalue(bonus.getenglishtranslatebonus());
hssfcell = hssfrow.createcell(12);
hssfcell.setcellvalue(bonus.getactualtotalbonus());
rowindex++;
}
byte[] bytes = typeutils.hssfworkbooktobytearray(hssfworkbook);
return bytes;
}
- 2楼网友:躲不过心动
- 2021-01-10 03:42
保存为超链接即可
这样即使在Excel里面也可以通过超链接打开该图片的链接进行查看
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯