How to set up hyperlinks in Excel cells using java

This article mainly introduces how to use java to set up hyperlinks in Excel cells. It is introduced in great detail through example code, which has certain reference value for everyone's study or work. Friends in need can refer to it

(1) Problem introduction

Sometimes when we import data into excel, we may need to set a hyperlink to a file or picture, such as linking to an Internet or a local directory. We can implement it through Java code with the help of POI library.

(2) Solution

Reference code examples are given directly below:

File file;
Workbook wb = new XSSFWorkbook(file);
Sheet sheet = wb.getSheet("sheet名称");
Row row = sheet.getRow(行号);
Cell cell = row.getCell(列号);
String name = "超链接";cell.setCellValue(name);
CreationHelper creationHelper = workbook.getCreationHelper();
Hyperlink link = creationHelper.createHyperlink(HyperlinkType.FILE);String url = "http://www.baidu.com";
link.setAddress(url);
cell.setHyperlink(link);
Font font = workbook.createFont();
font.setColor(IndexedColors.BLUE.getIndex());
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.cloneStyleFrom(cell.getCellStyle());
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);

The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>