c# 打开*.doc
来源:百度知道 编辑:UC知道 时间:2024/05/23 17:36:06
怎样把一个word文档里的东西导入到textbox或其他类似容器里,重要的是一定要能把word文档里的图片也导入到里面,这个程序是windowsapplincation的,不是web的.问题解决,给追加分.
Word.ApplicationClass word = new Word.ApplicationClass();
Type wordType = word.GetType();
Word.Documents docs = word.Documents;
// 打开文件
Type docsType = docs.GetType();
object filename = "c:\\";
Word.Document doc = (Word.Document)docsType.InvokeMember("Open",System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {filename, true, true});
// 转换格式,另存为
Type docType = doc.GetType();
object saveFileName = Server.MapPath("../") + "OfficeFile\\HTML\\"+ "aa.html";
//下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成:
//docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML});
///其它格式:
///wdFormatHTML
///wdFormatDocument
///wdFormatDOSText
///wdFormatDOSTextLineBre