如何将excel,word等office文件转为html文本再显示带页面上
Response.ContentType = "Application/msword";//Response.ContentType = "appliation/octet-stream";Response.ClearContent();Response.ContentEncoding = System.Text.Encoding.Default;Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode((byte[])dt.Rows[0][0]));Response.BinaryWrite((byte[])dt.Rows[0][0]);
c#如何把word文档转成html
日常生活中,我们总是在Word中进行文字的编辑,它不仅能够保存Text文本,还可以保存文本的格式等等。
那么如果我要将一Word文档上的内容展示在网页上,该怎么做呢?这里我提供了一个小工具,你可以将Word转换为Html,需要显示的话,可以直接访问该Html,废话不多说,下面看代码。
页面代码:[html] view plaincopy C#代码:[csharp] view plaincopyusing System; using System.Data; using System.Configuration; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; protected void Page_Load(object sender, EventArgs e) { } /// /// 将word转换为Html /// /// /// protected void btnConvert_Click(object sender, EventArgs e) { try { //上传 //uploadWord(File1); //转换 wordToHtml(File1); } catch (Exception ex) { throw ex; } finally { Response.Write("恭喜,转换成功!"); } } //上传文件并转换为html wordToHtml(wordFilePath) /// ///上传文件并转存为html /// ///word文档在客户机的位置 ///上传的html文件的地址 public string wordToHtml(System.Web.UI.HtmlControls.HtmlInputFile wordFilePath) { Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass(); Type wordType = word.GetType(); Microsoft.Office.Interop.Word.Documents docs = word.Documents; // 打开文件 Type docsType = docs.GetType(); //应当先把文件上传至服务器然后再解析文件为html string filePath = uploadWord(wordFilePath); //判断是否上传文件成功 if (filePath == "0") return "0"; //判断是否为word文件 if (filePath == "1") return "1"; object fileName = filePath; 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 }); // 转换格式,另存为html Type docType = doc.GetType(); string filename = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString(); // 判断指定目录下是否存在文件夹,如果不存在,则创建 if (!Directory.Exists(Server.MapPath("~\\html"))) { // 创建up文件夹 Directory.CreateDirectory(Server.MapPath("~\\html")); } //被转换的html文档保存的位置 string ConfigPath = HttpContext.Current.Server.MapPath("html/" + filename + ".html"); object saveFileName = ConfigPath; /*下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成: * docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, * null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML}); * 其它格式: * wdFormatHTML * wdFormatDocument * wdFormatDOSText * wdFormatDOSTextLineBreaks * wdFormatEncodedText * wdFormatRTF * wdFormatTemplate * wdFormatText * wdFormatTextLineBreaks * wdFormatUnicodeText */ docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML }); //关闭文档 docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { null, null, null }); // 退出 Word wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null); //转到新生成的页面 return ("/" + filename + ".html"); } public string uploadWord(System.Web.UI.HtmlControls.HtmlInputFile uploadFiles) { if (uploadFiles.PostedFile != null) { string fileName = uploadFiles.PostedFile.FileName; int extendNameIndex = fileName.LastIndexOf("."); string extendName = fileName.Substring(extendNameIndex); string newName = ""; try { //验证是否为word格式 if (extendName == ".doc" || extendName == ".docx") { DateTime now = DateTime.Now; newName = now.DayOfYear.ToString() + uploadFiles.PostedFile.ContentLength.ToString(); // 判断指定目录下是否存在文件夹,如果不存在,则创建 if (!Directory.Exists(Server.MapPath("~\\wordTmp"))) { // 创建up文件夹 Directory.CreateDirectory(Server.MapPath("~\\wordTmp")); } //上传路径 指当前上传页面的同一级的目录下面的wordTmp路径 uploadFiles.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("wordTmp/"...
如何迅速将Word转换为Html
//将Word转换为Htmlpublic string wordToHtml(System.Web.UI.HtmlControls.HtmlInputFile wordFilePath){Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();Type wordType = word.GetType();Microsoft.Office.Interop.Word.Documents docs = word.Documents; // 打开文件Type docsType = docs.GetType(); //应当先把文件上传至服务器然后再解析文件为html//if (wordFilePath.PostedFile != null)//{ //变换前路径 改动1//string filePath = ViewState["sss"].ToString();//} string filePath = File1.PostedFile.FileName;object fileName = filePath; 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 }); // 转换格式,另存为htmlType docType = doc.GetType();string filename = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() +System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString(); //被转换的html文档保存的位置string ConfigPath = AppDomain.CurrentDomain.BaseDirectory.ToString() + "Uploadfiles \\wordTmp\\" + filename + ".html";object saveFileName = ConfigPath; docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,null, doc, new object[]{ saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML }); // 退出 WordwordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);//转到新生成的页面
word文档怎么设置目录,点击即可转到所需内容
1、word文档可以通过引用设置目录。
2、步骤如下,第一,选中文字将其制作目录第二,将其样式变为“标题”第三、四、五,点击“引用”,“目录”,“自动插入目录1”第六,已做好目录。
如何将HTML格式转化为word
打开 HTML 文件,点击菜单栏 文件→使用 Microsoft Office Word 编辑,之后系统会自动打开 Word 并显示HTML文件的内容,这是保存即可。
如果找不到“使用 Microsoft Office Word 编辑”的话,点击菜单栏 工具→Internet 选项→程序→ HTML 编辑器 → Microsoft Office Word → 确定。
word转为Html错误!“times”附近有语法错误是什么意思?
一、把要发布的内容粘贴到记事本里面,然后在粘贴到网页在线编辑器里面,这样可以避免格式错误。
? ? ? 二、以FreeTextBox为例,将FreeTextBox1.Text替换为FreeTextBox1.Text.Replace("'", "''")问题就可以得到解决,其他网页编辑器的方法也是一样的。
请教,如何将WORD文档转换成“已编译的HTML文件”
我知道2种办法能够实现doc文档批量的转换HTMl格式. 1 word 2000 以上的版本自身就能够实现这样的功能.但是有时候可能产生一些不知道什么原因造成的垃圾码. 2 使用现成的免费软件.叫做. A: 功能和介绍 你喜欢制作chm电子书吗?想把文件批量转换为网页格式吗?想要一个漂亮的电子相册吗?... 主要功能:网页制作,网页批量转换,电子书制作,文件分割合并,文件加密解密,分述如下: 1、文本文件 批量转换为 网页文件 (txt 等转换为 htm) 2、网页文件 批量转换为 文本文件 (htm 等转换为 txt) 3、WORD、EXCEL、POWERPOINT 文档 批量转换为 网页文件(doc xls ppt 等转换为 htm) 4、图片文件、FLASH、mp3 ,wmv文件 批量转换为 网页 (jpg gif swf mp3 wmv等--> htm) 5、支持 WORD(doc 文件) 一步生成电子书 (梦寐以求的 功能吧?呵呵。
。
。
) 6、可以作为一个 文本文件的 电子书制作工具软件。
(并可选择 网页模板或者CSS) 7、支持 图片文件一步 编译 为电子相册。
(并可选择 电子相册模板 或者 CSS) 8、支持 mht 文件 一步生成电子书 9、网页取色功能。
可以抓取屏幕上任何可见部分的颜色代码;目前 可抓取 三种格式的颜色 10、网页批量压缩功能。
可以选择性的或批量压缩网页文件 11、批量加密文件,也可以解密文件。
12、批量分割文件,还可以合并文件。
13、文档合并功能。
支持 多种文件格式合并为 HTML TXT RTF DOC 四种格式之一 14、支持 HTML 网页文件 一步 生成电子书。
15、网页特效收集管理功能。
并且可以方便的批量插入到网页中 16、反编译 CHM 电子书。
17、网上搜索功能。
与强大的中文搜索引擎---百度搜索整合 18、已经提供了 数个 CSS 和模板,注册后提供更多模板。
你也可自行编写。
使转换更随意 19、对 html 文件生成电子书 提供了两种选择 20、支持 ppt (powerpoint)文件一步生成电子书 21、支持 xls (excel)文件一步生成电子书 22、文本及网页文字 的批量替换 23、你除了可以转换上述列出的文件类型外,你也可以自己增加转换类型 B 下载地址: http://www.skycn.com/soft/14929.html 这是天空下载网站的地址.当然你可以用"王子网页转换小精灵 V1.2.6"作为题目自己搜索其他的地址
转载请注明出处51数据库 » 带目录word转html
乱世疯笔