2
我想在C#中自動執行一個任務,藉此循環訪問單詞(docx)文件中的圖像,並根據圖像名稱更改圖像(在選擇窗格下重命名)。 我似乎無法找到在哪裏訪問圖像的名稱屬性?如何從C#.NET中的MS Word訪問圖像名稱?
測試代碼:
using System;
using System.Collections.Generic;
using Word = Microsoft.Office.Interop.Word;
namespace wordReplace
{
class Program
{
private static Word.Application app;
private static object yes = true;
private static object no = false;
private static object missing = System.Reflection.Missing.Value;
static void Main(string[] args)
{
try
{
app = new Word.Application();
app.Visible = true;
Word.Document d;
object filename = @"C:\test.docx";
d = app.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<Word.Range>();
foreach (Word.InlineShape s in d.InlineShapes)
{
//need to access the image name property here!!
}
app.Quit(ref no, ref missing, ref missing);
}
catch (Exception x)
{
Console.WriteLine(x.Message);
app.Quit(ref no, ref missing, ref missing);
}
}
}
}
感謝您的答覆,但我沒有看到如何回答這個問題?我正在查找圖像名稱(因爲它出現在選擇窗格中:主頁功能區 - >編輯部分 - >選擇 - >選擇窗格...) – jk777