Word 2003 文書の MergeFields を置き換えるライブラリを作成しようとしましたが、置換するとフィールドに適用されたスタイルが失われることを除いて、すべて正常に動作します。それを保持する方法はありますか?
これは、フィールドを置き換えるために使用しているコードです。
private void FillFields2003(string template, Dictionary<string, string> values)
{
object missing = Missing.Value;
var application = new ApplicationClass();
var document = new Microsoft.Office.Interop.Word.Document();
try
{
// Open the file
foreach (Field mergeField in document.Fields)
{
if (mergeField.Type == WdFieldType.wdFieldMergeField)
{
string fieldText = mergeField.Code.Text;
string fieldName = Extensions.GetFieldName(fieldText);
if (values.ContainsKey(fieldName))
{
mergeField.Select();
application.Selection.TypeText(values[fieldName]);
}
}
}
document.Save();
}
finally
{
// Release resources
}
}
選択範囲で CopyFormat メソッドと PasteFormat メソッドを使用しようとしましたが、get_style と set_style も使用しましたが、程度はありませんでした。