将位图粘贴到页脚后 VSTO C# Word 崩溃
VSTO C# Word crashes after pasting bitmap to a footer
正在编写加载项。
尝试将 .resx 文件中的图像放在 Word 文档的页脚中。
由于 InlineShapes.addPicture
需要文件路径,我发现我可以使用剪贴板代替插入图片(只是暂时的),但是当使用 Paste() 时 Word 一直在崩溃。
它以代码 0 (0x0) 退出。
代码如下:
private void placeFooterNavigationOnce()
{
Word.Range footerRange = Globals.ThisAddIn.Application.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
Clipboard.SetImage(Resource1.Brackets);
footerRange.Select();
Globals.ThisAddIn.Application.Selection.Paste();
}
编辑-附加信息:
inlineShapes.addPicture
执行相同的任务,没有任何错误。
将图像粘贴到文档正文中也可以。
@MikeK,这是我在 VB.NET 解决方案中所做的,试图找出为什么位图的剪贴板 Copy/Paste 对我不起作用。我相信您可以将其调整为 C# 解决方案。
Dim img as Image, fName as String
fName = "rClock32"
img = My.Resources.ResourceManager.GetObject(fName)
img.Save(ThisAddIn.LGPUserTempDir & fName & ".png")
wApp.Selection.InlineShapes.AddPicture(ThisAddIn.LGPUserTempDir & fName & ".png")
Kill(ThisAddIn.LGPUserTempDir & fName)
img = Nothing
正在编写加载项。
尝试将 .resx 文件中的图像放在 Word 文档的页脚中。
由于 InlineShapes.addPicture
需要文件路径,我发现我可以使用剪贴板代替插入图片(只是暂时的),但是当使用 Paste() 时 Word 一直在崩溃。
它以代码 0 (0x0) 退出。
代码如下:
private void placeFooterNavigationOnce()
{
Word.Range footerRange = Globals.ThisAddIn.Application.ActiveDocument.Sections[1].Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
Clipboard.SetImage(Resource1.Brackets);
footerRange.Select();
Globals.ThisAddIn.Application.Selection.Paste();
}
编辑-附加信息:
inlineShapes.addPicture
执行相同的任务,没有任何错误。
将图像粘贴到文档正文中也可以。
@MikeK,这是我在 VB.NET 解决方案中所做的,试图找出为什么位图的剪贴板 Copy/Paste 对我不起作用。我相信您可以将其调整为 C# 解决方案。
Dim img as Image, fName as String
fName = "rClock32"
img = My.Resources.ResourceManager.GetObject(fName)
img.Save(ThisAddIn.LGPUserTempDir & fName & ".png")
wApp.Selection.InlineShapes.AddPicture(ThisAddIn.LGPUserTempDir & fName & ".png")
Kill(ThisAddIn.LGPUserTempDir & fName)
img = Nothing