EPPlus批量插入图片到Excel
#region 测试EPPlus插入图片
public static void Createsheel2()
{
WebClient client = new WebClient();
var downloadUrl = FileOperater.GetDownloadUrl("f736cf1950e64400b3ba69001b0b5a1b");
var excelData = client.DownloadData(downloadUrl);
var bytes = client.DownloadData("http://img1.soufunimg.com/message/images/card/tuanproj/201511/2015112703584458_s.jpg");
using (Stream ms = new MemoryStream(excelData))
{
ExcelPackage excel;
try
{
excel = new ExcelPackage(ms);
ExcelWorksheet ws = excel.Workbook.Worksheets[1];
ExcelWorkbook wb = excel.Workbook;
for (int i = 1; i < 7; i++)
{
excel.Workbook.Worksheets.Copy(ws.Name, ws.Name+"_"+i);//复制模板sheet
var drawings = excel.Workbook.Worksheets[i].Drawings;
foreach (ExcelDrawing excelDrawing in drawings)
{
ExcelPicture excelPicture = excelDrawing as ExcelPicture;
var name = excelPicture.Name;
//var aa = excelPicture.Image;
//var cc = excelPicture.ImageFormat;
//excelPicture.Image.Save(imgms, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
int vSheetCount = excel.Workbook.Worksheets.Count; //获取总Sheet页
for (int i = 1; i <= vSheetCount; i++)
{
ws = excel.Workbook.Worksheets[i];
using (Stream imgms = new MemoryStream(bytes))
{
System.Drawing.Bitmap myimge = new System.Drawing.Bitmap(imgms);
ExcelPicture picture = null;
for (int j = 0; j <4; j++)
{
picture = ws.Drawings.AddPicture("a" + j, myimge);//插入图片
if (j >1)
{
picture.SetPosition(560, 250 * (j - 2) + (j - 1) * 40);//设置图片的位置
}
else
{
picture.SetPosition(330, 250 * j +(j+1)*40);//设置图片的位置
}
// picture.SetPosition(100*j, 100*j);//设置图片的位置
picture.SetSize(250, 220);//设置图片的大小
}
}
}
FileOperater.FileUpdate("f736cf1950e64400b3ba69001b0b5a1b", excel.GetAsByteArray());
}
catch (Exception ex)
{
throw;
}
}
}
#endregion
推荐阅读
-
Java实现批量导入excel表格数据到数据库中的方法
-
datatable生成excel和excel插入图片示例详解
-
PHP 批量下传图片 怎么保存路径到mysql
-
java poi导出图片到excel示例代码
-
PHP上传Excel并批量添加数据到pgsql的有关问题,期待高人解答
-
把Excel 里的图片批量导出来不要一张一张地截图
-
php中使用ExcelFileParser处理excel获得数据(可作批量导入到数据库使用)
-
ExcelFileParser处理excel获得数据 可作批量导入到数据库_PHP教程
-
请教大神,使用js在文本段落后插入div图片容器,结果图片却显示到段落前了,代码如下。非常感谢!_html/css_WEB-ITnose
-
同时上传批量图片到七牛和S3,S3没什么问题,七牛经常发生超时,求解