3
Word 2003 문서에서 MergeFields를 바꾸기 위해 라이브러리를 만들려고했지만 대체 할 때 필드에 적용된 스타일을 잃어 버리는 것을 제외하고는 모든 것이 잘 작동합니다. 그것을 지킬 수있는 방법이 있습니까?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
}
}
나는 또한 get_style 및 set_style하지만 exent에를 사용하여, 선택에 CopyFormat 및 PasteFormat 방법을 사용하여 시도 :
이
내가 필드를 대체하기 위해 사용하고 코드입니다. 대신 필드의 결과 속성을 사용하여 선택의 맨 위에 TypeText를 사용
안녕 이것은 많은 도움이되었습니다. 감사. 올바른 형식은 mergeField.Result.Text = (values [fieldName])입니다. 결과 유형이 "범위"이기 때문에. 고마워요 – willvv
예, f.Result.Text, 말씀하신대로. – hawbsl
효과가 있지만 결과는 의도하지 않습니다. 내 코드는'{MERGEFIELD ClientName * Upper}'입니다. 그러나 병합 실행 후 클라이언트 이름 대문자 표시되지 않습니다. 너 나 좀 도와 줄 수있어? 고맙습니다. –