c# - 文字自动化:如何使用 C# 替换形状而不是 InlineShape 的图像
问题描述
我找到了一个很好的链接,它给出了用新图片替换 word 文档的内部形状的好例子,但是我们如何使用形状对象而不是内部形状对象来做同样的事情。
using System.Collections.Generic;
using Word = Microsoft.Office.Interop.Word;
namespace WordExample
{
class WordExample
{
#region Constructor
public WordExample()
{
WordApp = new Microsoft.Office.Interop.Word.Application();
}
#endregion
#region Fields
private Word.Application WordApp;
private object missing = System.Reflection.Missing.Value;
private object yes = true;
private object no = false;
private Word.Document d;
private object filename = @"C:\FullPathToFile\example.doc";
#endregion
#region Methods
public void UpdateDoc()
{
d = WordApp.Documents.Open(ref filename, ref missing, ref no, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref yes, ref missing, ref missing, ref missing, ref missing);
List<Word.Range> ranges = new List<Microsoft.Office.Interop.Word.Range>();
foreach (Word.InlineShape s in d.InlineShapes)
{
if (s.Type == Microsoft.Office.Interop.Word.WdInlineShapeType.wdInlineShapePicture)
{
ranges.Add(s.Range);
s.Delete();
}
}
foreach (Word.Range r in ranges)
{
r.InlineShapes.AddPicture(@"c:\PathToNewImage\Image.jpg", ref missing, ref missing, ref missing);
}
WordApp.Quit(ref yes, ref missing, ref missing);
}
#endregion
}
}
我试图通过将形状转换为内部形状来做到这一点,但是当我改变图像的位置时,我没有找到任何合适的方式直接在形状中进行操作。
解决方案
推荐阅读
- python - 将列名转移到模板python
- android - Android沿着路径拖动视图
- python - Python BeautifulSoup 在同一行输出两个 Div 类值
- webview - 在 webview 中使用密码打开 pdf
- laravel - 如何在使用 ErickTamayo/laravel-scout-elastic 时将自定义选项传递给搜索方法?
- http - SFTP 服务器将数据推送到 http 后端
- react-native - 如何使用 expo StoreReview.requestReview()
- c# - 思考技术分析指标的正确设计
- r - 根据R中的分组内索引/级别插入编号列
- spring-boot - 尝试使用 open api 生成代码时未找到符号错误