POI在导出的EXCEL中嵌入图片
2012-11-08 12:46
417 查看
string filename = ComMethod.ObjToString(Table1.Rows[index]["files"]);
if (!string.IsNullOrEmpty(filename))
{
string path = Server.MapPath(ConfigurationManager.AppSettings["ArtworkFile"]);
string readpath = path + filename;
FileInfo file = new System.IO.FileInfo(readpath);
if (!file.Exists)
{
ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('" + readpath + ",该文档不存在!');</script>");
}
byte[] bytes = System.IO.File.ReadAllBytes(readpath); //byte[] bytes = System.IO.File.ReadAllBytes("E:\\ttt\\Chrysanthemum.jpg"); int pictureIdx = hssfworkbook.AddPicture(bytes, PictureType.JPEG);
// Create the drawing patriarch. This is the top level container for all shapes. HSSFPatriarch patriarch = (HSSFPatriarch)excelSheet.CreateDrawingPatriarch();
//add a picture,hssfclientanchor包含8个参数,其中,后面四个参数分别指嵌入图片的位置 HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 1023, 0, (short)(2 + tablesize.Rows.Count), 5, 11, (short)(startrow + deletecount1));
patriarch.CreatePicture(anchor, pictureIdx); }
if (!string.IsNullOrEmpty(filename))
{
string path = Server.MapPath(ConfigurationManager.AppSettings["ArtworkFile"]);
string readpath = path + filename;
FileInfo file = new System.IO.FileInfo(readpath);
if (!file.Exists)
{
ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('" + readpath + ",该文档不存在!');</script>");
}
byte[] bytes = System.IO.File.ReadAllBytes(readpath); //byte[] bytes = System.IO.File.ReadAllBytes("E:\\ttt\\Chrysanthemum.jpg"); int pictureIdx = hssfworkbook.AddPicture(bytes, PictureType.JPEG);
// Create the drawing patriarch. This is the top level container for all shapes. HSSFPatriarch patriarch = (HSSFPatriarch)excelSheet.CreateDrawingPatriarch();
//add a picture,hssfclientanchor包含8个参数,其中,后面四个参数分别指嵌入图片的位置 HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 1023, 0, (short)(2 + tablesize.Rows.Count), 5, 11, (short)(startrow + deletecount1));
patriarch.CreatePicture(anchor, pictureIdx); }
相关文章推荐
- POI导出Excel文件图片丢失问题解决
- POI导出Excel 含一维码图片
- poi导出Excel与项目的结合-案例(包含图片的设置)
- POI导出图片到Excel 用的Jar包是POI3.10 & JFreechart1.0.17
- POI模板导出EXCEL并且插入图片
- poi导出Excel与项目的结合-案例(包含图片的设置)
- poi导出Excel中图片的设置
- 将图片导出到Excel中(poi导出)
- java POI导出excel(带有图片的数据)以及ftp上传图片到另一台服务器的方法参考代码
- POI导出图片到EXCEL
- 将eChart图片利用POI导出到Excel
- JAVA POI自动导出数据和图片到excel
- 使用POI生成Excel文件及使用POI在EXCEL文件中插入图片的方法
- 利用POI将数据导出到EXCEL模板
- POI 导出excel
- C# 实现Excel导出图片
- POI导出Exel表中图片到文件夹下
- poi导出百万数据到excel
- struts2 poi 把数据导出到excel
- Java 使用POI导出Excel文件