HSSFWorkbook hssfworkbook = new HSSFWorkbook(); var sheet1 = hssfworkbook.CreateSheet("第一个Sheet"); //图片的操作 byte[] bytes = System.IO.File.ReadAllBytes(@"D:\test.jpg"); int pictureIdx = hssfworkbook.AddPicture(bytes, PictureType.JPEG); HSSFPatriarch patriarch = (HSSFPatriarch)sheet1.CreateDrawingPatriarch(); HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, 0, 0, 3, 3); HSSFPicture pict = (HSSFPicture)patriarch.CreatePicture(anchor, pictureIdx); //保存 FileStream file = new FileStream("D:/test.xls", FileMode.Create); hssfworkbook.Write(file); file.Close();
如果看不懂 HSSFClientAnchor方法
参考https://www.cnblogs.com/1175429393wljblog/p/9809868.html
这个是介绍这个方法的 很详细 ,这里就不写了! 如果你鼠标以上去看的懂就不用来问,看不懂就访问链接去查看,更不用来问了