如何将Excel中的元素(图表)定位到某个单元格?

时间:2022-10-10 22:20:12

I have a chart in Excel that I need to position (move) into certain cell.

我在Excel中有一个图表,我需要将其定位(移动)到某个单元格中。

I'm looking for something along these lines:

我正在寻找这些方面的东西:

procedure TMyExcelClass.MyProcedure;
var
  sheet, chartObject: Variant;
begin
  sheet := fExcel.ActiveWorkBook.Sheets['Some sheet'];
  chartObject := sheet.ChartObjects[1];
  chartObject.Left := <Left of cell "F">
  chartObject.Top := <Top of cell "34">
end;

How do I do position chart object to certain cell? (taking into account, that cells might have different widths and heights)

如何将图表对象定位到某个单元格? (考虑到,细胞可能有不同的宽度和高度)

1 个解决方案

#1


4  

Create a range of the cell you want to locate the chart to. Then assign the left and top properties of the range to the chart object.

创建要将图表定位到的单元格范围。然后将范围的左侧和顶部属性分配给图表对象。

procedure TMyExcelClass.MyProcedure;
var
  sheet, chartObject, r: Variant;
begin
  sheet := fExcel.ActiveWorkBook.Sheets['Some sheet'];

  r := sheet.Range['F34'];

  chartObject := sheet.ChartObjects[1];
  chartObject.Left := r.Left;
  chartObject.Top := r.Top
end;

#1


4  

Create a range of the cell you want to locate the chart to. Then assign the left and top properties of the range to the chart object.

创建要将图表定位到的单元格范围。然后将范围的左侧和顶部属性分配给图表对象。

procedure TMyExcelClass.MyProcedure;
var
  sheet, chartObject, r: Variant;
begin
  sheet := fExcel.ActiveWorkBook.Sheets['Some sheet'];

  r := sheet.Range['F34'];

  chartObject := sheet.ChartObjects[1];
  chartObject.Left := r.Left;
  chartObject.Top := r.Top
end;