我正在做个html文件转word格式下载的问题,现在出现的问题,html的图片转成word后,如果不联网,不能显示,应该是word文件里存储的还是图片的链接地址,而没有改变为word的存储方式,请问这个问题该怎样解决?

解决方案 »

  1.   

    无法解决。那也根本不是什么“world格式”文件,纯粹是你把文件名的后缀改成doc(或者docx),这就叫做“word格式文件”了?糊弄咱们那些一点不懂的客户也许可以,糊弄自己可不行。既然根本不是word格式文件,既然就是html内容,那么就遵循html的规矩,html上图片表达式就是一个链接的。
      

  2.   

    正好最近在弄这个,有两个办法,第一个是把你生成的"word"文件打开后再另存一下,存储为DOC格式的,WORD程序会自动把图片嵌入进去,前后文件大小也会有变化另外一个办法是用ASPOSE.WORDS控件来处理,下面是示例的代码,内容和文件名是通过表单POST过来的:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Aspose.Words;
    using System.Text.RegularExpressions;
    using System.Net;
    using System.IO;
    using System.Text;public partial class Bom2_exportWord : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string html = Request.Form["content"].ToString();
            string filename = Request.Form["filename"].ToString();
            string hostpath = Request.Url.AbsoluteUri.ToString().Substring(0, Request.Url.AbsoluteUri.ToString().Length - Request.Url.LocalPath.ToString().Length+1);
            Regex rx = new Regex(@"(?<=src="")(.*?)(?="")", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            html = rx.Replace(html, hostpath + "$1");
            rx = new Regex(@"(?<=href="")(.*?)(?="")", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            html = rx.Replace(html, hostpath + "$1");        //TextBox1.Text = html;
            //return;
            Document doc = new Document();
            doc.ViewOptions.ViewType = Aspose.Words.ViewType.Web;
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.InsertHtml(html);
            foreach (Aspose.Words.Section section in doc)
            {
                section.PageSetup.TopMargin = 20;
                section.PageSetup.BottomMargin = 20;
                section.PageSetup.LeftMargin = 20;
                section.PageSetup.RightMargin = 20;
            }
            Response.Clear();
            Request.Url.Host.ToString();
            doc.Save(filename, SaveFormat.Doc, SaveType.OpenInWord, Response);
        }
    }
      

  3.   

    今天在网上看了个 Aspose.Words.dll 说可以解决这个问题,想试验一下,用regsvr32 Aspose.Words.dll 操作的时候显示没有输入点,请问这个问题怎样解决啊