【问题标题】:Get selected excel cell获取选中的excel单元格
【发布时间】:2014-06-04 15:38:19
【问题描述】:

我正在尝试将某些内容粘贴到特定的 Excel 单元格中, 但有时它会将数据粘贴到其他地方。

 workSheet = ExcelApp.Worksheets[2] as Excel._Worksheet;
             Grd_Dep_In.SelectAll();
            Grd_Dep_In.Copy();
            Excel.Range DepIn = cellsRange.get_Range("a2");
            DepIn.Select();
            workSheet.Paste();

有时它会粘贴在 A2 中,有时则不会。

所以我想检查 a2 是否是选定的单元格。

在我开始粘贴之前。 我的代码在 8 个工作表中复制并生成数据透视表。有时它会搞砸并复制到 Excel 工作表中的其他位置。

所以我需要什么:

if (activeCell= A2)
{
paste

}

但我不知道如何确定活动的 Excel 单元格。

【问题讨论】:

标签: c# excel


【解决方案1】:

试试这个:

Excel.Range rng = (Excel.Range) this.Application.ActiveCell;
int row = rng.Row;
int column = rng.Column;

if (row == 1 && column == 1)
{
  // paste
}

【讨论】:

  • 这么简单 :) 非常感谢 ;D
猜你喜欢
  • 1970-01-01
  • 2013-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多