我目前正在尝试创建并保存Outlook签名 问题是,它总是以一种“默认”编码保存 尝试以编程方式将多个位置更改为UTF-8(!)似乎不起作用。
我认为正确的位置只是对WebOptions
的更改,因为在检查前一个值时其他编码已经设置为UTF-8。
实际上是否有办法更改编码并让Outlook以这种方式保存?
这是一个展示问题的示例:
using Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
namespace CreateSignature
{
class TestCreation
{
static void Main(string[] args)
{
Create();
}
public static void Create()
{
const string _LineBreak = "\v";
string signature = string.Empty;
Application word = new Application();
var document = word.Documents.Add();
var selection = word.Selection;
word.Options.DefaultTextEncoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
document.WebOptions.Encoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
selection.Font.Bold = 0;
selection.Font.Name = "Verdana";
selection.Font.Size = 9;
selection.Font.Color = WdColor.wdColorBlack;
selection.TypeText("Best regards");
selection.TypeText(_LineBreak);
selection.TypeText("Special text ### üäöß····· ###");
selection.TypeText(_LineBreak);
document.SaveEncoding = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
document.Saved = true;
var signatureName = "Test.Signature";
var emailOptions = word.EmailOptions.EmailSignature;
emailOptions.EmailSignatureEntries.Add(signatureName, document.Range());
//emailOptions.NewMessageSignature = signatureName;
//emailOptions.ReplyMessageSignature = signatureName;
word.Quit(WdSaveOptions.wdSaveChanges);
Marshal.ReleaseComObject(word);
}
}
}
.htm
文件将包含此
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
它应该是utf-8
而不是windows-1252
。
this question似乎很熟悉,虽然这不是一个已加载的文档,但建议的更改无论如何都不起作用(Fields.Count == 0
)。