打开RTF文件时出现安全警告

时间:2020-10-02 14:55:44

标签: c# .net rtf word

我已将多个RTF文件合并为一个RTF文件,并保存了单个RTF文件。多个RTF文件中包含图像。我已使用Interop.word Microsoft Office库将多个RTF文件合并为一个RTF文件。当我尝试使用写字板打开该Single RTF文件时,它显示安全警告,并要求“取消阻止”和“阻止”内容。单个RTF文件中包含图片。打开RTF文件时,它不信任RTF文件中的图像内容。

我使用了这个Nuget软件包:

Microsoft.Office.Interop.Word-版本15.0.4797.1003

public static void Merge(string[] filesToMerge, string outputFilename, bool insertPageBreaks)
{
object missing = System.Type.Missing;
object pageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdSectionBreakNextPage;
object outputFile = outputFilename;
Microsoft.Office.Interop.Word._Application wordApplication = new Microsoft.Office.Interop.Word.Application();
try
{
Microsoft.Office.Interop.Word.Document wordDocument = wordApplication.Documents.Add(
ref missing
, ref missing
, ref missing
, ref missing);
Microsoft.Office.Interop.Word.Selection selection = wordApplication.Selection;
int documentCount = filesToMerge.Length;
int breakStop = 0;
foreach (string file in filesToMerge)
{
breakStop++;
selection.InsertFile(file, ref missing, ref missing, ref missing, ref missing);
if (insertPageBreaks && breakStop != documentCount)
{
selection.InsertBreak(ref pageBreak);
}
}
wordDocument.SaveAs(
ref outputFile
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing
, ref missing);
wordDocument = null;
}
catch (Exception ex)
{
throw ex;
}
finally
{
wordApplication.Quit(ref missing, ref missing, ref missing);
}
}

enter image description here

0 个答案:

没有答案