以下是把页面中的数据导出word的方法,求页面中的图片怎样导出???public void ExpertControl(System.Web.UI.Control source, DocumentType type)
    {
        //设置Http的头信息,编码格式
        if (type == DocumentType.Excel)
        {
            //Excel
            Response.AppendHeader("Content-Disposition", "attachment;filename=result.xls");
            Response.ContentType = "application/ms-excel";
        }
        else if (type == DocumentType.Word)
        {
            //Word
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("送货单", System.Text.Encoding.UTF8).ToString() + ".doc");
            Response.ContentType = "application/ms-word";
        }
        Response.Charset = "gb2312";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
        //关闭控件的视图状态
        source.Page.EnableViewState = false;
        //初始化HtmlWriter
        System.IO.StringWriter writer = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
        source.RenderControl(htmlWriter);
        //输出
        Response.Write(writer.ToString());
        Response.End();
    }
    //文档类型枚举
    public enum DocumentType
    {
        Word,
        Excel
    }

解决方案 »

  1.   


    用xml方式保存成WORD,把图片内容读出来变成base64编码放到XML你先熟悉下WORD转出XML结构的样子
      

  2.   

    下面是我把通过sql查出的datatable中的图片保存到本地,然后在把这个图片导入到word的方法,方法很笨,仅供参考:
     //如果此人有照片的话,导入到word
                    if (ds.Tables[0].Rows[0]["照片"].ToString() !="")
                    {
                        //将数据库中的照片保存到本地
                        byte[] img_bytes = (byte[])ds.Tables[0].Rows[0]["照片"]; //图片字段
                        string img_path = System.Windows.Forms.Application.StartupPath + "\\img.jpg";
                        System.IO.FileStream fs = new System.IO.FileStream(img_path, FileMode.CreateNew);
                        fs.Write(img_bytes, 0, img_bytes.Length);
                        fs.Flush();
                        fs.Close();
                        //添加照片到word
                        object range = newTable.Cell(2, 5).Range;
                        object linkToFile = false;
                        object saveWithDocument = true;
                        wordDoc.InlineShapes.AddPicture(img_path, ref linkToFile, ref saveWithDocument, ref range);                    wordDoc.Application.ActiveDocument.InlineShapes[1].Width = 97f;//图片宽度
                        wordDoc.Application.ActiveDocument.InlineShapes[1].Height = 139f;//图片高度
                    }
    这里的ds是我自己定义的dataset,也就是通过sql查出的数据
      

  3.   

    不好意思,代码中本来想对ds加红色处理着,但是居然显示了红色的标签,再贴一下代码:  //如果此人有照片的话,导入到word
                    if (ds.Tables[0].Rows[0]["照片"].ToString() !="")
                    {
                        //将数据库中的照片保存到本地
                        byte[] img_bytes = (byte[])ds.Tables[0].Rows[0]["照片"]; //图片字段
                        string img_path = System.Windows.Forms.Application.StartupPath + "\\img.jpg";
                        System.IO.FileStream fs = new System.IO.FileStream(img_path, FileMode.CreateNew);
                        fs.Write(img_bytes, 0, img_bytes.Length);
                        fs.Flush();
                        fs.Close();
                        //添加照片到word
                        object range = newTable.Cell(2, 5).Range;
                        object linkToFile = false;
                        object saveWithDocument = true;
                        wordDoc.InlineShapes.AddPicture(img_path, ref linkToFile, ref saveWithDocument, ref range);                    wordDoc.Application.ActiveDocument.InlineShapes[1].Width = 97f;//图片宽度
                        wordDoc.Application.ActiveDocument.InlineShapes[1].Height = 139f;//图片高度
                    }
                    下面是关于worDoc的初始化:            object Nothing = System.Reflection.Missing.Value;
                Word.Application wordApp = new Word.ApplicationClass();
                wordApp.Visible = false;
                Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
      

  4.   

    用lz的那种好像要先保存流,然后转换输出,至于保存到word 没搞过