读书人

C# docs文件转换成html解决方案

发布时间: 2012-06-28 15:20:04 作者: rapoo

C# docs文件转换成html
我的代码是想把word文件转换成html
但是我现在的代码只能将doc转换成html
但是office 2007 2010 的文件docs就不能转换了
求大神帮忙看一下
还有个问题是这个程序关闭时怎么删除刚生成的temp.html文件。

C# code
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using Microsoft.Office.Interop.Word;using System.IO;namespace WindowsFormsApplication1{    public partial class Form1 : Form     {        public Form1()        {            InitializeComponent();            main();        }        private void main()        {            Microsoft.Office.Interop.Word.Application word = new ApplicationClass();            Type wordType = word.GetType();            Microsoft.Office.Interop.Word.Documents docs = word.Documents;            Type docsType = docs.GetType();            object fileName = "D://Test.docs";            Microsoft.Office.Interop.Word.Document doc = (Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });            Type docType = doc.GetType();            object saveFileName = "D://temp.html";            docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, WdSaveFormat.wdFormatHTML });            wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);        }    }}


[解决办法]
保存方法的一个参数可以指定格式的
[解决办法]
收分 多写楼主.

docx吧

读书人网 >C#

热点推荐