1

我正在尝试将放入我的 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); 
}
4

1 回答 1

3

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

例如

Width = float.Parse(cell.MergeArea.Width.ToString());
Height = float.Parse(cell.MergeArea.Height.ToString());
于 2012-08-03T09:42:31.793 回答