Save as Document Object
尝试在 C# 中实现单词自动化时出现以下错误:
System.Runtime.InteropServices.COMException
(0x80020005):类型不匹配。(来自 HRESULT 的异常:0x80020005 (DISP_E_TYPEMISMATCH))
at Microsoft.Office.Interop.Word.DocumentClass.SaveAs(Object&
FileName, Object& FileFormat, Object& LockComments, Object& Password, Object& AddToRecentFiles, Object& WritePassword, Object& ReadOnlyRecommended, Object& EmbedTrueTypeFonts, Object& SaveNativePictureFormat, Object& SaveFormsData, Object& SaveAsAOCELetter, Object& Encoding, Object& InsertLineBreaks, Object& AllowSubstitutions, Object& LineEnding, Object& AddBiDiMarks)
at TestWordAutomation.Form1.SaveAs(String
文件名)在 D:\dotnet\WordAutomation\TestWordAutomation\TestWordAutomation\Form1.cs:line 246
at TestWordAutomation.Form1.button4_Click(Object
发件人,EventArgs e) 在 D:\dotnet\WordAutomation\TestWordAutomation\TestWordAutomation\Form1.cs:line 557
我这样调用Save As
方法:
MySaveAs("Doc1.doc");
MySaveAs("Doc2.doc");
MySaveAs("Doc3.doc");
//I have a MySaveAs function
public void MySaveAs(string fileName)
{
object FileName = null, FileFormat = null, LockComments = null, _Password = null, AddToRecentFiles = null, _WritePassword = null, _ReadOnlyRecommended = null, _EmbedTrueTypeFonts = null, SaveNativePictureFormat = null, _SaveFormsData = null, SaveAsAOCELetter = null, Encoding = null, InsertLineBreaks = null, AllowSubstitutions = null, LineEnding = null, AddBiDiMarks = null;
FileName = (object) fileName;
oDoc.SaveAs(ref FileName, ref FileFormat, ref LockComments, ref _Password, ref AddToRecentFiles,
ref _WritePassword, ref _ReadOnlyRecommended, ref _EmbedTrueTypeFonts,
ref SaveNativePictureFormat, ref _SaveFormsData, ref SaveAsAOCELetter, ref Encoding,
ref InsertLineBreaks, ref AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
}
谁能帮我解决这个问题?