Byte[] Image To Excel
方法一
rng_area.Select();
byte[] image = (byte[])sdr.Tables[er.TableName].Rows[0][er.CellName];
Image c = Image.FromStream(new MemoryStream(image));
Clipboard.SetDataObject(c, false);
xlSheet.Paste(rng_area, c);
//取消纵横比
xlApp.Selection.ShapeRange.LockAspectRatio = false;
//设定图片高度
xlApp.Selection.ShapeRange.Height = rng_area.MergeArea.Height - 1;
//设定图片宽度
xlApp.Selection.ShapeRange.Width = rng_area.MergeArea.Width - 1;
//左面增加 1
xlApp.Selection.ShapeRange.IncrementLeft(1);
//上面增加 1
xlApp.Selection.ShapeRange.IncrementTop(1);
方法二
#region AddPicture
rng_area.Select();
byte[] image = (byte[])sdr.Tables[er.TableName].Rows[0][er.CellName];
Image c = Image.FromStream(new MemoryStream(image));
string fileName ="c:\\temp\\" +DateTime.Now.ToString("HHmmssfff")+".jpg";
c.Save(fileName);
xlSheet.Shapes.AddPicture(fileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, rng_area.Left+1, rng_area.Top+1, rng_area.MergeArea.Width-1, rng_area.MergeArea.Height-1);
if (File.Exists(fileName))
{
File.Delete(fileName);
}
#endregion
评论