C# word转换成HTML
来源:互联网 发布:终极迈凯伦数据 编辑:程序博客网 时间:2024/06/06 13:02
C# word转换成HTML
添加com引用Microsoft word 11.0 Object Library
添加using System.Threading;using System.IO;
//实例化一个Word
Microsoft.Office.Interop.Word.ApplicationClass appclass = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordtype = appclass.GetType();
Microsoft.Office.Interop.Word.Documents docs = appclass.Documents;//获取Document
Type docstype = docs.GetType();
object filename = @"E:/AA.doc";//Word文件的路径
Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docstype.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new object[] { filename, true, true });//打开文件
Type doctype = doc.GetType();
object savefilename = @"E:/bb.html";//生成HTML的路径和名子
doctype.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { savefilename, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });//另存为Html格式
wordtype.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, appclass, null);//退出
Thread.Sleep(3000);//为了使退出完全,这里阻塞3秒
StreamReader objreader = new StreamReader(savefilename.ToString(), System.Text.Encoding.GetEncoding("GB2312"));
//以下内容是为了在Html中加入对本身Word文件的下载
FileStream fs = new FileStream(savefilename.ToString().Split('.').GetValue(0).ToString() + "$.html", FileMode.Create);
StreamWriter streamHtmlHelp = new System.IO.StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
//streamHtmlHelp.WriteLine("<a href='E://AA.html'>源文件下载</a><br>");
string str = "";
do
{
str = objreader.ReadLine();
streamHtmlHelp.WriteLine(str);
}
while (str != "</html>");
streamHtmlHelp.Close();
objreader.Close();
File.Delete(savefilename.ToString());
File.Move(savefilename.ToString().Split('.').GetValue(0).ToString() + "$.html", savefilename.ToString());
- C# word转换成HTML
- C#把Word文档转换成HTML
- C# 将Word,Excel转换成Html
- Word转换成Html
- word转换成html
- C# 将Word文档转换为HTML
- C# 将Word文档转换为HTML
- java word转换成html
- word&excel转换成html
- word批量转换成html
- c#使用代码将html转换为word
- 如何把word文档转换成html
- 将WORD文件转换成HTML文件
- Word转换成Html或Xml
- jacob读取word excel,转换成html
- 把word,excel转换成 Html
- 将WORD文件转换成HTML文件
- openoffice 将word文档转换成html
- 一个简单的VB.net程序
- ASP.NET页面刷新的实现方法:
- 垂直搜索引擎发展的几个方向
- qrcode的编码 qrcode解码
- LUA的数组迭代器实现
- C# word转换成HTML
- Ubuntu安装KVM虚拟机
- 开发JSP程序
- Windows下用ActivePerl的PPM安装Perl模块
- 关于.NET软件工程师面试题
- 驾校考试秘笈 不用看书就能通过!! 暂时不考也先留着 别等着急的时候没处找
- java中使用sqlite数据库
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- Solaris 10学习笔记