我正在尝试自动调整我放入excel的图片大小到那里的单元格大小,但是它给了我原始的高度和宽度,而不是高度和整个合并单元格。
我正在使用Microsoft.Office.Interop.Excel与我的工作簿和电子表格进行交互。
//This is checking if is a photo
if (File.Exists(ArrayNode[i].TagValue))
{
float Left, Top, Width, Height;
Left = float.Parse(cell.Left.ToString());
Top = float.Parse(cell.Top.ToString());
//This gives me the width and height of the cell, but i need it for the merged cells.
Width = float.Parse(cell.Width.ToString());
Height = float.Parse(cell.Height.ToString());
String path = Application.StartupPath + "\\" + ArrayNode[i].TagValue;
xlWorkSheet[k].Shapes.AddPicture(path, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, Left, Top, Width, Height);
}
答案 0 :(得分:3)
要使用合并的单元格放置图片,您必须获取.MergeArea.Width
和.MergeArea.Height
例如
Width = float.Parse(cell.MergeArea.Width.ToString());
Height = float.Parse(cell.MergeArea.Height.ToString());