c# 打开word

添加using System.Reflection; using Microsoft.Office.Interop.Word; 引用

在d盘下建立1.doc文档作为测试 

string filepath = "D://1.doc";             Microsoft.Office.Interop.Word.Application oword = new Microsoft.Office.Interop.Word.Application();           //  oword.Documents = new Microsoft.Office.Interop.Word.Document();  

           //oword.Documents= oword.Application.Documents.Open(filepath, ref Missing.Value , System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value);             Object filename = filepath;             Object ConfirmConversions = false;             Object ReadOnly = false;             Object AddToRecentFiles = false;             Object PasswordDocument = System.Type.Missing;             Object PasswordTemplate = System.Type.Missing;             Object Revert = System.Type.Missing;             Object WritePasswordDocument = System.Type.Missing;             Object WritePasswordTemplate = System.Type.Missing;             Object Format = System.Type.Missing;             Object Encoding = System.Type.Missing;             Object Visible = System.Type.Missing;             Object OpenAndRepair = System.Type.Missing;             Object DocumentDirection = System.Type.Missing;             Object NoEncodingDialog = System.Type.Missing;             Object XMLTransform=System.Type.Missing;             oword.Documents.Open(ref filename, ref ConfirmConversions,             ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,             ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,             ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog, ref XMLTransform);             //wordDoc = wordApp.Documents.Open(ref filename, ref ConfirmConversions,             //ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,             //ref Revert,ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,             //ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog);               oword.Visible = true; 调试成功!

总结一下,如果调用用原来的excel的System.Reflection.Missing.Value默认缺省值就不行,调用word的时候必须使用System.Type.Missing默认缺省值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值