利用 Aspose.Words 组件,在不依赖与 Office 组件的情况下把 Word 文件转换成 HTML 代码。
2018-05-03 11:07
423 查看
首先利用 Nuget 获取 Aspose.Words.dll
public ActionResult AsposeWordsDemo() { string srcFileName = Server.MapPath("~/Data/a.doc"); Document doc = new Document(srcFileName); string basicDirVirtualPath = "/UploadFiles/"; string tempDir = Server.MapPath(basicDirVirtualPath); HtmlSaveOptions saveOptions = new HtmlSaveOptions(); // Specify folder where images will be saved. saveOptions.ImagesFolder = tempDir; // We want the images in the HTML to be referenced in the e-mail as attachments so add the cid prefix to the image file name. // This replaces what would be the path to the image with the "cid" prefix. saveOptions.ImagesFolderAlias = basicDirVirtualPath; // Header footers don't normally export well in HTML format so remove them. saveOptions.ExportHeadersFootersMode = ExportHeadersFootersMode.None; // saveOptions.ExportHeadersFooters = false; // 老版本用这个 // Save the document to stream in HTML format. MemoryStream htmlStream = new MemoryStream(); doc.Save(htmlStream, saveOptions); // Read the HTML from the stream as plain text. string htmlText = Encoding.UTF8.GetString(htmlStream.ToArray()); htmlStream.Close(); // Save the HTML into the temporary folder. string htmlFileNameWithoutPath = "Message.html"; Stream htmlFile = new FileStream(Path.Combine(tempDir, htmlFileNameWithoutPath), FileMode.Create); StreamWriter htmlWriter = new StreamWriter(htmlFile); htmlWriter.Write(htmlText); htmlWriter.Close(); htmlFile.Close(); return Redirect(basicDirVirtualPath + htmlFileNameWithoutPath); }
相关文章推荐
- 示例代码:利用Sps提供的remoting服务,把office文档在线转换成html文档(包括页面图片的文件)
- 将WORD文档转换成为HTML网页文件的C#代码
- c#实现word,excel转pdf代码及部分Office 2007文件格式转换为xps和pdf代码整理
- Java利用aspose-words将word文档转换成pdf(破解 无水印)
- 利用Aspose.Words处理Word文档之间的转换和内容操作
- 利用C#代码将html样式文件与Word文档互换的方法
- [转]Aspose.Words.dll 将 Word 转换成 html
- jsp 转换成word的文件代码(转换成的是假doc文件,内容还是html)
- JAVA 使用Aspose.Words组件生产Word或PDF文件
- OFFICE(word/ppt/excel)转换成HTML实现
- C#调用OFFICE转换WORD,EXCEL,PPT文件为PDF
- 利用OpenOffice/LibreOffice将office文件转换成pdf
- excel(word)文件中的表格如何快速转化为html代码
- Asp.net中将Word文件转换成HTML的方法
- C#中利用Aspose.Words直接将数据写到word里
- Atitit.office word excel ppt pdf 的web在线预览方案与html转换方案 attilax 总结
- 代码示例:调用SPS提供的remoting服务,在线把Office文档转换成html文档
- C#使用指定打印机打印Word,Excel等Office文件和打印PDF文件的代码
- 利用Java把word的文件转换成htm文件
- 将HTML或txt文件转换为ASP输出的vbs代码