Ms word 在OpenXML中从Word断开超链接图像
我试图打破所有的超链接的图像留下的图像在文件中。在word界面中,可以手动保存文档中的图像,但我已经尝试在代码中找到一种直接执行的方法。我在excel中找到了这篇文章,但没有在Word中找到: 根据这些信息,我尝试了以下方法:Ms word 在OpenXML中从Word断开超链接图像,ms-word,openxml,openxml-sdk,Ms Word,Openxml,Openxml Sdk,我试图打破所有的超链接的图像留下的图像在文件中。在word界面中,可以手动保存文档中的图像,但我已经尝试在代码中找到一种直接执行的方法。我在excel中找到了这篇文章,但没有在Word中找到: 根据这些信息,我尝试了以下方法: internal static void BreakLinks(WordprocessingDocument document) { var hyperLinkCollection = document.MainDocumentPart.Docum
internal static void BreakLinks(WordprocessingDocument document)
{
var hyperLinkCollection = document.MainDocumentPart.Document.Body.Descendants<Hyperlink>().First();//.Body.Descendants<Hyperlink>().First();
if (hyperLinkCollection.Any())
{
var hyperLinks = hyperLinkCollection.Descendants<Hyperlink>();
foreach (var hyperLink in hyperLinks)
{
document.MainDocumentPart.DeleteReferenceRelationship(hyperLink.Id);
//remove cell style using hyperLink.Reference
}
hyperLinkCollection.Remove();
document.MainDocumentPart.Document.Save();
}
}
内部静态无效断开链接(WordprocessingDocument)
{
var hyperLinkCollection=document.MainDocumentPart.document.Body.subjects().First();/.Body.subjects().First();
if(hyperLinkCollection.Any())
{
var hyperLinks=hyperLinkCollection.subjects();
foreach(超链接中的var超链接)
{
document.MainDocumentPart.DeleteReferenceRelationship(hyperLink.Id);
//使用hyperLink.Reference删除单元格样式
}
hyperLinkCollection.Remove();
document.MainDocumentPart.document.Save();
}
}
使用此代码,找不到任何超链接。
有什么帮助吗?提前感谢。您确定它们是超链接而不是INCLUDEPICTURE字段吗?