猿问

Savedoc2在保存docx文件C#时出现错误

我一直在尝试使用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)引发了System.Runtime.InteropServices.COMException:“服务器引发了异常。来自HRESULT的异常:0x80010105(RPC_E_SERVERFAULT))“时间:2018/4/22 11:39:12 PM线程:[9556]


请告诉我我在这里做错了什么?


守着星空守着你
浏览 278回答 1
1回答

江户川乱折腾

好的,我有问题。Saveas2仅用于Microsoft Office 2010,解决此问题的方法仅是使用Saveas而不是Saveas2。
随时随地看视频慕课网APP
我要回答