邮件合并爱尔兰法达的

时间:2017-06-21 10:45:26

标签: c# character-encoding mailmerge mojibake

我有一个文本文件,我用它作为邮件合并模板的数据源。爱尔兰法达字符(á,Á,ó,Ó,ú,Ú,í,Í,é,É)在输出文件中被转换为乱码。

我的代码如下:

var path  = "c:\template.docx";
var _dataSourcePath = "c:\source.txt";

_wrdDoc = _wrdApp.Documents.Open(path, ReadOnly: true,OpenAndRepair: true);

wrdMailMerge.OpenDataSource(_dataSourcePath, ref oFalse, ref oTrue, ref oMissing,
                                                        ref oMissing, ref oMissing,
                                                        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                                        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                                        ref oTrue, ref oMissing);

_wrdDoc.MailMerge.SuppressBlankLines = true;


wrdMailMerge.DataSource.FirstRecord = startingRecord;
wrdMailMerge.DataSource.LastRecord = endingRecord;

_wrdApp.Options.CheckSpellingAsYouType = false;
_wrdApp.Options.CheckGrammarAsYouType = false;

_wrdApp.Options.SuggestSpellingCorrections = false;
_wrdApp.Options.CheckGrammarWithSpelling = false;
_wrdApp.ActiveDocument.ShowSpellingErrors = false;
_wrdDoc.ShowSpellingErrors = false;
_wrdDoc.ShowGrammaticalErrors = false;


_wrdDoc.SpellingChecked = true;
_wrdDoc.GrammarChecked = true;
// Perform mail merge.
try
{
    WriteError("Merge Ready to execute");
    wrdMailMerge.Destination = WdMailMergeDestination.wdSendToNewDocument;
    wrdMailMerge.Execute(ref _oFalse);
    WriteError("Merge Executed.");

}
catch(Exception ex)
{
    WriteError(ex.StackTrace);
    throw new Exception("There was a problem Merging the document");
    CleanUp();
    return;
}

我在.OpenDataSource期间尝试了各种编码选项,但似乎都没有。我需要改变什么?

0 个答案:

没有答案