c# - 使用 word-interop 将图像添加到 word
问题描述
我正在尝试使用超链接插入图像以下是我的代码
Microsoft.Office.Interop.Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();
WordApp.Documents.Add();
WordApp.Visible = true;
Microsoft.Office.Interop.Word.Document doc = WordApp.ActiveDocument;
Microsoft.Office.Interop.Word.Range drange = doc.Range();
Microsoft.Office.Interop.Word.InlineShape picture =
drange.InlineShapes.AddPicture("c:\\logo.png", Type.Missing, Type.Missing, Type.Missing);
// noew add the hyperlink to object of inlineshape
drange.Hyperlinks.Add(picture, "http:\\www.google.com", Type.Missing, Type.Missing, Type.Missing, Type.Missing);
解决方案
Microsoft.Office.Interop.Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
Microsoft.Office.Interop.Word.Application objApplication = Globals.ThisAddIn.Application;
Microsoft.Office.Interop.Word.Selection objSelection = objApplication.Selection;
Microsoft.Office.Interop.Word.Paragraphs p = objSelection.Paragraphs;
Microsoft.Office.Interop.Word.Range objRange = objSelection.Range;
Microsoft.Office.Interop.Word.InlineShape ils = objRange.InlineShapes.AddPicture(@"C:\..\image.PNG");
float scaledWidth = ils.Width;
float scaledHeight = ils.Height;
推荐阅读
- java - 为什么 Windows 和 macOS/Linux 之间的 sleep(1) 的 CPU 使用率存在很大差异?
- asp.net-core - 从信息日志级别的内存缓存消息中删除响应
- windows - 清除 Flutter for Desktop (Windows) 应用程序的数据
- python - 'async_generator 不是可调用对象' FastAPI 依赖问题应用程序
- bash - 如何检测应用程序何时使用 bash 打开?有带陷阱的事件吗?
- javascript - 为什么 removeChild 会删除每个元素而不是只删除一个元素?
- react-native - React Native Searchable Dropdown 显示空白字段
- sapui5 - 如何根据 UI5 中的值格式化表内的文本字段?
- variables - 如何成功启动 vsim 命令?即使它在 CentOS 8 的 PATH 环境变量中也找不到
- javascript - 带有 HTML 符号的 SVG 到 Canvas