https://www.cnblogs.com/Ajoying/p/8005032.htmlfor(int i = 0; i < GoodList.Count; i++){string name = GoodList[i].title;string cover = GoodList[i].cover;using(WebClient client = new WebClient()){//client.DownloadFile(new Uri(cover), $"{rootPath}\\{name}.png");// ORtry{client.DownloadFile(new Uri(cover), $ "{rootPath}\\{i+1}.jpeg");Thread.Sleep(50);}catch(Exception ex){Console.WriteLine(ex.Message);}}this.BeginInvoke(new Action(() =>{MyProgressBar.Value = i;}));}
3、把缓存的图片插入到指定的单元格内:
string imagePath = $ "{AppDomain.CurrentDomain.BaseDirectory}Cache\\{rowIndex}.jpeg";//从本地获取var bytes = File.ReadAllBytes(imagePath);if(bytes != && bytes.Length != 0){//byte[] bytes = System.IO.File.ReadAllBytes(datarow["picture"].ToString());int pictureIdx = workbook.AddPicture(bytes, PictureType.JPEG);HSSFPatriarch patriarch = (HSSFPatriarch) sheet.CreateDrawingPatriarch();HSSFClientAnchor anchor = new HSSFClientAnchor(70, 40, 0, 0, 1, rowIndex, 0, rowIndex + 1);//把图片插到相应的位置HSSFPicture pict = (HSSFPicture) patriarch.CreatePicture(anchor, pictureIdx);// 指定我想要的长宽double standardWidth = 220;double standardHeight = 100;// 计算单元格的长宽double cellWidth = sheet.GetColumnWidthInPixels(cell.ColumnIndex);double cellHeight = cell.Row.HeightInPoints / 72 * 96;// 计算需要的长宽比例的系数double a = standardWidth / cellWidth;double b = standardHeight / cellHeight;pict.Resize(a, b);}
最终简单的效果先这样吧;以后有时间的话,可以再去摸索一下更复杂的效果;编程不息、Bug不止、无Bug、无生活;改bug的冷静、编码的激情、完成后的喜悦、挖坑的激动 、填坑的兴奋;这也许就是屌丝程序员的乐趣吧;今天就到这里吧;希望自己有动力一步一步坚持下去;生命不息,代码不止;大家抽空可以看看今天分享的效果,有好的意见和想法,可以在留言板随意留言;我看到后会第一时间回复大家,多谢大家的一直默默的关注和支持!
