NPOI导出excel,插入图片

//add picture data to this workbook.

byte[] bytes = System.IO.File.ReadAllBytes(@"D:\MyProject\NPOIDemo\ShapeImage\image1.jpg");

int pictureIdx = hssfworkbook.AddPicture(bytes, HSSFWorkbook.PICTURE_TYPE_JPEG);



//create sheet

HSSFSheet sheet = hssfworkbook.CreateSheet("Sheet1");



// Create the drawing patriarch.  This is the top level container for all shapes. 

HSSFPatriarch patriarch = sheet.CreateDrawingPatriarch();



//add a picture

HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 1023, 0, 0, 0, 1, 3);

HSSFPicture pict = patriarch.CreatePicture(anchor, pictureIdx);


 

 

有时并不需要拉伸的效果

在结尾加上pict.Resize();即可使图片自动伸缩到原始大小了

 

你可能感兴趣的:(NPOI导出excel,插入图片)