简体   繁体   English

如何在Java中使用openxml将Hypelink创建到Excel中

[英]How to create Hypelink into Excel using openxml in Java

I am trying to add hyperlink to excel file from OpenXML, which I am not able to. 我试图将超链接从OpenXML添加到excel文件,但我无法这样做。 Have read somewhere that need to add relationships tag for hyperlink and then refer that id with hyperlink tag, but how to add this relationship tag is I am not getting. 已经读过需要为超链接添加关系标签,然后用超链接标签引用该ID的地方,但是如何添加此关系标签却不是我所理解的。 Kindly provide me sample code or any guidance as to how to achieve it. 请为我提供示例代码或有关如何实现的任何指导。

You don't need to worry about the relationships or anything like that, POI will take care of it all for you. 您无需担心关系或诸如此类的事情,POI将为您解决所有这些问题。

The code to add a hyperlink is the same for HSSF (.xls) and XSSF (.xlsx), and is included on the POI website: http://poi.apache.org/spreadsheet/quick-guide.html#Hyperlinks 用于添加超链接的代码与HSSF(.xls)和XSSF(.xlsx)相同,并且包含在POI网站上: http ://poi.apache.org/spreadsheet/quick-guide.html#Hyperlinks

The code is basically something like: 该代码基本上是这样的:

Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();

Sheet sheet = wb.createSheet("Hyperlinks");
cell = sheet.createRow(0).createCell(Cell.CELL_TYPE_STRING);
cell.setCellValue("URL Link");

Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
link.setAddress("http://poi.apache.org/");
cell.setHyperlink(link);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM