- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像这样的字符串
String uriString = "#'Tab1 Tab2'!A8";
URI uri = new URI(uriString);
此操作失败,因为它不是格式正确的 URI(有空格)。所以我改为
String uriString = "#'Tab1%20Tab2'!A8";
URI uri = new URI(uriString);
编码正确,但片段变为“'Tab1%20Tab2'!A8”
然后,在 Excel 中,链接(附加到图像)指向不存在的“Tab1%20Tab2'!A8”。
我尝试将构造函数更改为
URI uri = new URI(null,null,uriString,null,null)
结果,现在 Excel 上的链接是“%23'Tab1 Tab2'!A8”,该链接现在不起作用,因为它是现在已转换的主题标签。这让我发疯。
这是构建 URI 并设置链接的代码
String hyperlinkAddress = "#'"+destinationTab + "'!" + destinationCell + "";
hyperlinkAddress = hyperlinkAddress.replaceAll(" ", "%20");
URI hyperLinkUri;
try {
hyperLinkUri = new URI(hyperlinkAddress);
PackageRelationship packagerelationship = drawing.getPackagePart().addRelationship(hyperLinkUri,TargetMode.EXTERNAL, PackageRelationshipTypes.HYPERLINK_PART);
String rid = packagerelationship.getId();
if (cthyperlink == null) cthyperlink = ctnonvisualdrawingprops.addNewHlinkClick();
cthyperlink.setId(rid);
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
如何才能实现超链接中的空格只是一个空格并且 # 不会转换为 %23?
更新
显然,在 Office 365 中它显示 %23,而在 Office 2013 中则显示正确的名称文件
更新这是导出 Excel 时超链接之一在绘图 xml 中显示的方式。
<Relationship Id="rId28" Target="%23Coverage%20Summary%20(Pool)!A8" TargetMode="External" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"/>
但是,当我将链接悬停在 Excel 中时,链接显示为
file:///C:\Users\myname\download\%23Coverage Summary (Pool)!A8
因此,空格被正确替换,但 # URI 片段未被替换。在 Office 2013 中,同一文件中,%23 被替换为正确打开超链接的文件名
最佳答案
您似乎想要创建 HyperlinkType.DOCUMENT 的超链接它链接到工作表“Tab1 Tab2”中的单元格 A8
。
https://svn.apache.org/repos/asf/poi/tags/REL_3_17_FINAL/src/examples/src/org/apache/poi/xssf/usermodel/examples/中有一个如何创建不同类型超链接的示例。对于apache poi 3.17
,https://svn.apache.org/repos/asf/poi/tags/REL_4_1_2/src/examples/src/org/apache/poi/xssf/usermodel/examples/对于 apache poi 4.1.2 和 https://svn.apache.org/repos/asf/poi/tags/REL_5_0_0/src/examples/src/org/apache/poi/examples/xssf/usermodel/对于apache poi 5.0.0
。
以下摘录仅显示适用于您的用例的完整代码示例:
import java.io.FileOutputStream;
import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//See https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/HyperlinkExample.java
public class HyperlinkTypeDocumentExample {
public static void main(String[]args) throws Exception {
try (Workbook wb = new XSSFWorkbook()) { //or new HSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
//cell style for hyperlinks
//by default hyperlinks are blue and underlined
CellStyle hlink_style = wb.createCellStyle();
Font hlink_font = wb.createFont();
hlink_font.setUnderline(Font.U_SINGLE);
hlink_font.setColor(IndexedColors.BLUE.getIndex());
hlink_style.setFont(hlink_font);
Cell cell;
Sheet sheet = wb.createSheet("Hyperlinks");
//URL
cell = sheet.createRow(0).createCell(0);
cell.setCellValue("URL Link");
//link to a place in this workbook
//create a target sheet and cell
Sheet sheet2 = wb.createSheet("Tab1 Tab2");
sheet2.createRow(7).createCell(0).setCellValue("Target Cell");
cell = sheet.createRow(1).createCell(0);
cell.setCellValue("Worksheet Link");
Hyperlink link = createHelper.createHyperlink(HyperlinkType.DOCUMENT);
link.setAddress("'" + sheet2.getSheetName() + "'!A8");
cell.setHyperlink(link);
cell.setCellStyle(hlink_style);
try (FileOutputStream out = new FileOutputStream("Hyperinks.xlsx")) {
wb.write(out);
}
}
}
}
<小时/>
结果来自问题作者的评论,即超链接应位于图像上。但是,只有在工作表名称不包含任何空格的情况下,才可以将指向同一工作簿中另一个工作表的超链接插入到图像中。此处显示:Apache poi putting hyperlink in images .
对于图片(图像)上的链接,目标需要是 URI
,并且 URI
必须是 URI 编码的。因此,如果工作表名称包含空格,则需要将其编码为 %20
。因此 #'Tab1 Tab2'!A8
需要是 #'Tab1%20Tab2'!A8
。但 Excel
本身违反了这些规则,因为它期望目标为 #'Tab1 Tab2'!A8
。我看不到任何使用 apache poi
生成错误 URI
的方法。
关于java - Excel 超链接 URI 片段未编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61251131/
使用 ruby 1.9.2-p290。我在尝试解析如下 URI 时遇到问题: require 'uri' my_uri = "http://www.anyserver.com/getdata?anyp
根据 http://tools.ietf.org/html/rfc3986和 http://en.wikipedia.org/wiki/Uniform_resource_identifier , UR
如何在文本 block 中发现 URI? 这个想法是将这样的文本运行变成链接。如果只考虑 http(s) 和 ftp(s) 方案,这很容易做到;但是,我猜测一般问题(考虑 tel、mailto 和其他
我的一些网址上有一些特殊字符。例如: http://blabla.com/title/?t=burası 当我从其他页面提供指向该页面的链接时,我使用: URI.encode(s) 产生这个链接: /
我在 Windows Mobile 上使用紧凑型框架/C#。 在我的应用程序中,我通过序列化对象并使用 HttpWebRequest/POST 请求向上发送信息来将数据上传到服务器。在服务器上,发布数
我正在做一个实验,我发现将 Canvas 转换为 blob,然后转换为数据 URI 会导致与直接从 Canvas 获取数据 URI 不同的 URI。打开时的内容在两个 URI 上几乎相同。 使用 bl
我正在尝试在 Rails 3 中实现 OAuth 提供程序。当我尝试授权客户端应用程序时,出现此错误。我正在使用 RESTful auth 插件和 pelles OAuth 插件。当我通过 Rails
我有一个编码的 UI 测试方法: public void MyTestMethod() { string baseUrl = "www.google.com"; GlobalVaria
我知道这是一个常见的错误,我正在使用一个已知的解决方案,但它仍然给我同样的错误: require 'open-uri' url = "http://website.com/dirs/filex[a]"
我正在尝试使用 .NET 中的 HttpClient 来使用 Web 服务,并且在我完成了 msdn 中提到的所有步骤之后 o 出现以下异常:提供了无效的请求 URI。请求 URI 必须是绝对 URI
我正在尝试检索文件的 URI。该文件存储在: /storage/emulated/0/AppName/FileName.png 如果我使用 Uri.fromFile(file),我得到的是 file:
我想知道 (SIP) URI 中的不同参数分隔符表示什么? 部分以;分隔,例如: . 其他用?隔开和 & ,例如: 最佳答案 SIP 分隔符规则来自RFC 2396 RFC 3986 已弃用.但是在
我想调用decodeUrl(...),我这样做是: import "dart:uri"; main() { decodeUrl("str"); } 但是现在有了最新的Dart-SDK,它会报告
在 URI 中,空格可以编码为 + .既然如此,那么在创建具有国际前缀的 tel URI 时是否应该对前导加号进行编码? 哪个更好?两者在实践中都有效吗? Call me Call me 最佳答案 不
我试图弄清楚电子邮件地址的格式是否可以说符合 URI 的定义,但到目前为止我还没有找到明确的确认。我希望有人可以在这里为我提供一些见解。预先感谢:) 最佳答案 是的,但带有“mailto:”前缀。 U
因此,我尝试将 ID 参数附加到 URI 的末尾,当用户单击我的列表中的项目时,用户将被发送到该 URI。我的代码如下: public void onItemClick(AdapterView par
这是 Converting file path to URI 的后续问题. 考虑: require 'uri' uri = URI.join('file:///', '/home/user/dir1/
我在 pl/sql 中创建了一个名为 tester 的包。但我收到以下消息。 绝对URI中的相对路径:java.net.URI.checkPath(URI.java:1823) --Package D
我在 gitlab 上有一个 git repo,使用私有(private) pod 和其他公共(public) pod,下面是我的 Podfile source 'git@gitlab.mycompa
我正在尝试将我的 Rails 应用程序推送到 heroku 上,我正在使用 heroku RedisToGo 附加组件我经历过这个tutorial并完成了那里提到的所有步骤。 但是在推送 heroku
我是一名优秀的程序员,十分优秀!