我有一个存储在服务器中的文件,路径如下:\\ myserver \ folder \ myfile.txt
如何将此SMB地址放在带超链接的单元格中?
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
link.setAddress("What to write here?");
当我使用以下代码时:
link.setAddress("\\\\myserver\\folder\\myfile.txt");
它返回错误:
Caused by: java.net.URISyntaxException: Illegal character in path at index 0: \\myserver\folder\myfile.txt
at java.net.URI$Parser.fail(Unknown Source)
at java.net.URI$Parser.checkChars(Unknown Source)
at java.net.URI$Parser.parseHierarchical(Unknown Source)
at java.net.URI$Parser.parse(Unknown Source)
at java.net.URI.<init>(Unknown Source)
at org.apache.poi.xssf.usermodel.XSSFHyperlink.validate(XSSFHyperlink.java:240)
... 2 more
答案 0 :(得分:3)
我认为你的术语可能会妨碍你的搜索。我相信这是UNC的道路。我不知道UNC如何与SMB联系,因为我更像是一个Linux人。但是,我成功地获得了以下代码
CreationHelper createHelper = workbook.getCreationHelper();
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
link.setAddress((new File ("\\\\myserver\\folder\\myfile.txt")).toURI().toString());
cell.setHyperlink(link);