如何使用固定名称保存文件? [英] How do I save a file using a fixed name?
问题描述
使用互操作Word的应用程序。 。 。下面的代码编译好了。 。但是当oDoc.SaveAs ....尝试执行时,类型不匹配错误。
以下是一些早期的定义。 。 。
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application() ;
感谢您提出任何修复建议。
********** ******
string sFileName =MYFILE;
object filename =C :\\ JR Temp\\+ sFileName +。。dococ;
object Missing = null;
//以下声明产生类型错误错误。 。 ????
oDoc.SaveAs(ref filename,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);
Application using interop Word . . . Code below compiles OK . . but type mismatch error when oDoc.SaveAs.... attempts to execute.
Here are some earlier definitions . . .
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
Thanks for any suggestion to fix.
****************
string sFileName = "MYFILE";
object filename = "C:\\JR Temp\\" + sFileName + ".docx";
object Missing = null;
//THE FOLLOWING STATEMENTS PRODUCES TYPE MISMATCH ERROR . . ???
oDoc.SaveAs(ref filename, 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);
推荐答案
我觉得参数的数量有一些你的在'SaveAs
'方法中提供。
I think there is something with the number of parameters you provided in 'SaveAs
' method.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Word;
namespace Test_InteropWord
{
class Program
{
static void Main(string[] args)
{
Application app = new Application();
Document doc = app.Documents.Add(Type.Missing,
Type.Missing,
WdDocumentType.wdTypeDocument, false);
doc.SaveAs(@"d:\tmp\test.docx");
((Microsoft.Office.Interop.Word._Document)doc).Close(true);
}
}
}
SaveAs方法:
< a href =http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document.saveas%28v=office.14%29.aspx> http://msdn.microsoft .com / zh-CN / library / microsoft.office.interop.word._document.saveas%28v = office.14%29.aspx [ ^ ]
[更新]
SaveAs method:
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word._document.saveas%28v=office.14%29.aspx[^]
[update]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// using Microsoft.Office.Interop.Word;
using MyWord = Microsoft.Office.Interop.Word;
namespace Test_InteropWord
{
class Program
{
static void Main(string[] args)
{
MyWord.Application app = new MyWord.Application();
MyWord.Document doc = app.Documents.Add(Type.Missing,
Type.Missing,
MyWord.WdDocumentType.wdTypeDocument, false);
doc.SaveAs(@"d:\tmp\test.docx");
((MyWord._Document)doc).Close(true);
}
}
}
当您引用该程序集中的任何类时,您可以与 MyWord
参考一起使用。
这篇关于如何使用固定名称保存文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!