我一直在尝试使用SaveAs2保存我的新word文档,但无法解决错误。 这是我保存文件的代码
word.Document newdocument = new word.Document();
newdocument = oword.Documents.Add(ref missing, ref missing, ref missing, ref missing);
word.Range rng = newdocument.Range(0, 0);
rng.Text = "start:\r\r" + content.Value.ToString();
rng.Text += "\rend:\r\r";
rng.Text += AnswerDictionary[content.Key.ToString()];
start = newdocument.Content.Start;
end = newdocument.Content.End;
range = newdocument.Range(ref start, ref end);
range.Select();
range.Font.Size = 11;
range.Font.Name = "Georgia";
rng.ParagraphFormat.Alignment = word.WdParagraphAlignment.wdAlignParagraphJustify;
rng.ParagraphFormat.LineSpacingRule = word.WdLineSpacing.wdLineSpaceDouble;
rng.ParagraphFormat.SpaceAfter = 0;
rng.ParagraphFormat.SpaceBefore = 0;
newfilename = @"C:\4PT\Output\" + content.Key.ToString() + ".docx";
//newdocument.SaveAs2(ref newfilename, 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, ref missing);
newdocument.SaveAs2(ref newfilename);
我收到此错误
异常:抛出:"服务器抛出异常。 (例外 HRESULT:0x80010105(RPC_E_SERVERFAULT))" (System.Runtime.InteropServices.COMException)A 抛出了System.Runtime.InteropServices.COMException:"服务器 抛出一个例外。 (HRESULT的例外情况:0x80010105 (RPC_E_SERVERFAULT))"时间:4/22/2018 11:39:12 PM主题:[9556]
请告诉我我在这里做错了什么?
答案 0 :(得分:0)
好的,我遇到了问题。 Saveas2仅适用于Microsoft Office 2010,此问题的解决方案仅使用Saveas而不是Saveas2。