【发布时间】:2011-01-06 16:51:48
【问题描述】:
Interop.Word 和 C# 存在一些图像问题。我想在要生成的文档的标题中添加一个图像。我的这段代码运行良好
section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Shapes.AddPicture(@"C:\Logo.jpg", ref x, ref x, ref x, ref x, ref x, ref x, ref x);
问题是我的代码中不能有"C:\Logo.jpg",因为发布项目后,用户的C文件夹中很可能没有Logo.jpg。该图像已经在我项目的资源文件夹中。我之前使用过Image.FromFile("Logo.jpg"),但.AddPicture 需要字符串而不是图像。
有什么想法吗?
-- 编辑--
在网上看到的:
string anyPath = @"C:\logo.jpg";
Properties.Resources.logo.Save(anyPath);
section.Headers.[...].Shapes.AddPicture(anyPath, ...
但我仍然在 GDI+ 中收到一般错误或 ExternalException 未处理。
【问题讨论】:
标签: c# image ms-word com-interop