获取合并单元格的高度和宽度以放置图片。

我正在尝试自动resize的图片到我的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); } 

要使用合并的单元格放置图片,您必须获取.MergeArea.Width.MergeArea.Height

例如

 Width = float.Parse(cell.MergeArea.Width.ToString()); Height = float.Parse(cell.MergeArea.Height.ToString());