private void SetWordDocumentPropertyValue(Word.Document document, string propertyName, string propertyValue) { try { object builtInProperties; builtInProperties = document.BuiltInDocumentProperties; Type builtInPropertiesType = builtInProperties.GetType(); object property = builtInPropertiesType.InvokeMember("Item", System.Reflection.BindingFlags.GetProperty, null, builtInProperties, new object[] { propertyName }); Type propertyType = property.GetType(); propertyType.InvokeMember("Value", BindingFlags.SetProperty, null, property, new object[] { propertyValue }); document.UpdateSummaryProperties(); document.Save(); } catch (COMException ex) { if (ex.ErrorCode == -2146824090) { // No problem, user just cancelled out of the save as dialog return; } } }
/// <summary> /// Documentを保存 /// </summary> /// <param name="doc">Document</param> public void Save(Word.Document doc) { doc.Save(); }
private static void ReplaceMailMergeField(Dictionary<string, string> dictionary, Word.Document document, Word.Application word) { word.Visible = false; DoReplaceMailMergeField(dictionary, document, word); document.Save(); word.Visible = true; word.Activate(); }