我想将单元格内的数据设置为链接:
public class TestExcelExport extends AbstractXlsxView {
@Override
protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception {
response.setHeader("Content-Disposition", "attachment; filename=\"export.xlsx\"");
Sheet sheet = workbook.createSheet("test");
Row row_1 = sheet.createRow(1);
row_1.createCell(0).setCellValue("some data");
}
}
如何使单元格数据成为指向系统目录中文件的链接?
答案 0 :(得分:1)
CreationHelper createHelper = workbook.getCreationHelper();
Cell cell = row_1.createCell((short)0);
cell.setCellValue("System File Link");
link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
link.setAddress("/usr/somedir/somefile.someext");
cell.setHyperlink(link);
这样做。