最近做项目发现,用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();
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();
解决方案 »
- C#如何获取一个汉字的拼音和五笔的首拼码呢????
- 行转列 排序问题?
- 急!!DXperience 怎么安装,怎么配置
- 如何通过修改DataGridView控件中值直接修改数据库中的值?
- 20090814新手求助?
- 昨天的面试题,分享一下。 大家也来答一下吧, (*^__^*) 嘻嘻……
- 请问怎样读取网页的指定内容呢?
- 高手来看看,调用dll之后,程序退出是总报错:1.引用的内存地址不能为“read”;2.runtime error 216 at xxxx
- 如何从全局缓存程序集中移除项?
- C#程序员能挣多少money?和java 比较呢?欢迎大家讨论!!
- 求助,关于WindowsSever的问题
- WritePrivateProfileString 的疑问
Tony Qu(http://tonyqus.cnblogs.com/)
Tony Qu(http://tonyqus.cnblogs.com/)
Tony Qu(http://tonyqus.cnblogs.com/)
Tony Qu(http://tonyqus.cnblogs.com/)