62,264
社区成员
发帖
与我相关
我的任务
分享
public void ApplicationTemplate(System.Collections.Hashtable ht, string strPath_Name)
{
object oMissing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word._Application app = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word._Document doc;
app.Visible = true;
try
{
// 打开 Dot
object fileName = strPath_Name;
object readOnly = false;
object isVisible = true;
doc = app.Documents.Open(ref fileName, ref oMissing, ref readOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref isVisible, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
if (ht != null)
{
for (int i = 1; i <= doc.Bookmarks.Count; i++)
{
object j = i;
string str = doc.Bookmarks.get_Item(ref j).Name;
if (ht[str] != null && ht[str].ToString().Length > 0)
{
Microsoft.Office.Interop.Word.Range rng = doc.Bookmarks.get_Item(ref j).Range;
rng.Text = ht[str].ToString();
object oRng = rng;
doc.Bookmarks.Add(str, ref oRng);
}
}
}
doc.Protect(Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyReading, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
}
catch (Exception e) { throw e; }
}