最近做项目发现,用npoi向包含图片的excel中插入图片后,再打开excel时会报数据丢失的错误模板中的图片是一个饼图是在excel中生成的请教大家看看怎么能解决,下面是代码,先谢谢了  #region 插入图片部分
            HSSFPatriarch patriarch = (HSSFPatriarch)sheet1.CreateDrawingPatriarch();
            HSSFClientAnchor anchor;
            anchor = new HSSFClientAnchor(0, 0, 0, 0, 0, 14, 0, 0);
            anchor.Dx1 = -3950;//设置图片边距宽度
            anchor.Dy1 = -1870;//设置图片边距高度
            anchor.AnchorType = 2;            //c#导出Excel 
            HSSFPicture picture = (HSSFPicture)patriarch.CreatePicture(anchor, LoadImage(2, hssfworkbook));
     
           
            picture.LineStyle = HSSFPicture.LINESTYLE_NONE;
            picture.Resize();
                       #endregion            //关闭文件
            sheet1.ForceFormulaRecalculation = true;
            MemoryStream ms = new MemoryStream();
            hssfworkbook.Write(ms);
            ms.Flush();
            ms.Position = 0;
            file.Close();
            //将结果流写到客户端去
            string strFilename = "attachment;filename=" + HttpUtility.UrlEncode(title1 + ".xls", System.Text.Encoding.UTF8).Replace("+", "%20");
            Response.Clear();
            Response.ClearHeaders();
            Response.Buffer = true;
            Response.AppendHeader("Content-Disposition", strFilename);
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Length", ms.GetBuffer().Length.ToString());
            Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
            Response.Flush();
            Response.End();

解决方案 »

  1.   

    NPOI文字部分用过很多,正常的,但图片部分没用过,帮楼主顶了
      

  2.   

    NPOI文字部分用过很多,正常的,但图片部分没用过,帮楼主顶了
      

  3.   

    你可以向原作者咨询一下,看看是写法有问题还是NPOI的bug
    Tony Qu(http://tonyqus.cnblogs.com/
      

  4.   

    你可以向原作者咨询一下,看看是写法有问题还是NPOI的bug
    Tony Qu(http://tonyqus.cnblogs.com/
      

  5.   

    你可以向原作者咨询一下,看看是写法有问题还是NPOI的bug
    Tony Qu(http://tonyqus.cnblogs.com/
      

  6.   

    你可以向原作者咨询一下,看看是写法有问题还是NPOI的bug
    Tony Qu(http://tonyqus.cnblogs.com/