zoukankan      html  css  js  c++  java
  • 利用 Aspose.Words 组件,在不依赖与 Office 组件的情况下把 Word 文件转换成 HTML 代码。

    首先利用 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);
    }
  • 相关阅读:
    网站 HTTP 升级 HTTPS 完全配置手册
    网站 HTTP 升级 HTTPS 完全配置手册
    负载均衡很难?看完这篇全懂了
    负载均衡很难?看完这篇全懂了
    负载均衡很难?看完这篇全懂了
    由浅入深,聊聊权限设计
    由浅入深,聊聊权限设计
    由浅入深,聊聊权限设计
    奇异值分解原理及Python实例
    写在西浦别离时
  • 原文地址:https://www.cnblogs.com/johnblogs/p/8984372.html
Copyright © 2011-2022 走看看