word转化html
来源:互联网 发布:微软雅黑light mac 编辑:程序博客网 时间:2024/06/05 00:48
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data.SqlClient;using Microsoft.Office.Interop.Word;using System.Reflection;using System.IO;using Word = Microsoft.Office.Interop.Word;public partial class Content : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { string SNo = Session["SNo"].ToString().Trim(); string data = Session["data"].ToString().Trim(); // string url = Geturl(SNo, DNo); string url = "~/Files/"+SNo+"/"+data+".doc"; string serverPath = Server.MapPath(url); string html = serverPath.Replace(".doc", ".html"); if (!File.Exists(@html)) //html页面不存在,把word转换成html { string filename = WordToHtml(serverPath); //StreamReader fread = new StreamReader(filename, System.Text.Encoding.GetEncoding("gb2312")); //string ss = fread.ReadToEnd(); //Response.Write(ss); //直接写字符串到网页会发现,文字可显示,图片、表格无法显示。因此在后面重跳转到html文件页面。 //fread.Close(); //fread.Dispose(); } // else { StreamReader fread = new StreamReader(html, System.Text.Encoding.GetEncoding("gb2312")); string ss = fread.ReadToEnd(); Response.Write(ss); //直接写字符串到网页会发现,文字可显示,图片、表格无法显示。因此在后面重跳转到html文件页面。 fread.Close(); fread.Dispose(); // } } //public string Geturl(string SNo, string DNo) //{ // Tool tool = new Tool(); // SqlConnection mycon = tool.Getconn(); // mycon.Open(); // string sql = "select Url from StudebtData where SNo = '" + SNo + "' and DNo = '" + DNo + "'"; // SqlCommand myCmd = new SqlCommand(sql, mycon); // SqlDataReader Dr = myCmd.ExecuteReader(); // Dr.Read(); // String Url = Dr["Url"].ToString().Trim(); // return Url; //} //将word转换html(带格式) private string WordToHtml(object wordFileName) { //在此处放置用户代码以初始化页面 Word.Application word = new Word.Application(); Type wordType = word.GetType(); Word.Documents docs = word.Documents; //打开文件 Type docsType = docs.GetType(); Word.Document doc = (Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFileName, true, true }); //转换格式,另存为 Type docType = doc.GetType(); string wordSaveFileName = wordFileName.ToString(); string strSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.Length - 3) + "html"; object saveFileName = (object)strSaveFileName; docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML }); docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null); //退出 Word wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null); return saveFileName.ToString(); }}
0 0
- word转化为html
- word转化html
- word 转化为HTML
- 将word怎么转化html
- Word格式转化为Html
- js实现word转化为html
- 将word文档转化为html(代码)
- 把Word文档转化为Html文件
- poi将word docx转化为html
- POI之Word转化为Html-yellowcong
- 将Word文档转化为HTML格式的文档
- 将Word文档转化为HTML格式的文档
- 将Word文档转化为HTML格式的文档
- C# 将Excel,ppt和word转化为html
- Word文档转化为HTML等其它格式
- 将Word文档转化为HTML格式的文档
- 将Word文档转化为HTML格式的文档
- 将Word文档转化为HTML格式的文档
- JS实时时间显示
- Linux(centos7) 源码安装cmake
- 八、机器学习系统设计笔记之对回归:改进的推荐
- CentOS7上安装MySQL Workbench
- VS2010 测试 -普通单元测试 http://www.cnblogs.com/rhythmK/archive/2012/04/20/2458832.html
- word转化html
- 九、机器学习系统设计笔记之分类III:音乐体裁分类
- 2015年6月数据库流行度排行榜
- Android应用程序注册广播接收器(registerReceiver)的过程分析
- Android ViewPager多页面滑动切换以及动画效果
- 图解Linux命令之--chown命令
- VLFeat 中SIFT算法的重新单独编译
- 策略模式
- 异步任务 AsyncTask 进度条的更新