// Create a new instance of Word
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;// Open a file
Type docsType = docs.GetType();
object fileName = "c:\\test2\\XP Embedded vs. Win CE.NET.doc";
Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
            
// Save a file
Type docType = doc.GetType();
object saveFileName = "c:\\test2\\XP Embedded vs. Win CE.NET";
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML});// Quit Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
 

解决方案 »

  1.   

    Word.ApplicationClass word = new Word.ApplicationClass();
    异常详细信息: System.UnauthorizedAccessException: 拒绝访问。 
    ASP.NET 帐户,在“允许”列中选中“写”框。以前相似的源代码总是出“无法打开宏储存”错误, 
    乱改一通,结果又在创建WORD应用程序时报错 
    Word.ApplicationClass word = new Word.ApplicationClass();
    这一句“要求asp.net写权限打开”, 
    我百分之百代开了写权限(IIS,IIS文件夹的,Word文档所在文件夹的都能写) 
    是不是Word的什么文件缓存没开写权限。
    why????  help!!!!!!!!! 分先给你。