简体   繁体   English

使用打开的 xml 将 [URL] 添加到 Excel 单元格中的图像

[英]Addin Link [URL] to an Image in Excel cell using open xml

I'm trying to use AddExternalRelationship method, but it doesn't work, simply I want to add Link to File [my file in this case is an image on a server] using openXML我试图用AddExternalRelationship方法,但它不工作,只是我想链接添加到文件[我在这种情况下,文件服务器上的图片]使用openXML

using (var newDoc = SpreadsheetDocument.Open(xlsDestFilePath, true)) {
    var run = new DocumentFormat.OpenXml.Spreadsheet.Run();
    var picture = new DocumentFormat.OpenXml.Spreadsheet.Picture();
    var shape = new DocumentFormat.OpenXml.Vml.Shape() {
        Id = "_x0000_i1025",
        Style = "width:453.5pt;height:270.8pt"
    };
    run.Append(picture);
    newDoc.AddHyperlinkRelationship(
        new Uri("URL GOES HERE", System.UriKind.Absolute), true);
}

Use AddHyperlinkRelationship使用AddHyperlinkRelationship

It is clearly stated in the msdn documentation to not use AddExternalRelationship msdn 文档中明确说明不使用AddExternalRelationship

Refer: https://msdn.microsoft.com/en-us/library/office/cc562653.aspx参考: https : //msdn.microsoft.com/en-us/library/office/cc562653.aspx

public HyperlinkRelationship AddHyperlinkRelationship(
    Uri hyperlinkUri,
    bool isExternal,
    string id
)

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

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