如何在excel中alignment图片
我使用下面的代码在Excel单元格中插入图像,但结果不被忽视
bitmap[] ImageArray = GetImageArray(); bitmap currvalue = null; System.Windows.Forms.Clipboard.SetDataObject(ImageArray[0], true); currvalue = ImageArray[0]; currentRange.Cells.HorizontalAlignment =Excel.XlHAlign.xlHAlignCenterAcrossSelection; currentRange.Cells.VerticalAlignment = Excel.XlHAlign.xlHAlignCenter; excelWorkSheet.Paste(currentRange.Cells, currvalue); excelWorkSheet.Columns.AutoFit();
这是输出
我不能使用objSheet.Shapes.AddPicture();
我想要图像中心alignment
在粘贴到excel seheet之后,需要通过代码调整单元格中图像的位置。 像下面的东西,HTH
excelWorkSheet.Paste(currentRange.Cells, currvalue); foreach (var shp in excelWorkSheet.Shapes) { if (shp.TopLeftCell.Address != currentRange.Address) continue; shp.Left = shp.TopLeftCell.Left + (shp.TopLeftCell.Width - shp.Width) / 2; shp.Top = shp.TopLeftCell.Top + (shp.TopLeftCell.Height - shp.Height) / 2; break; }