使用C#在Excel中关注单元格

我正在创build一个电子表格,收集站点的数据并将数据插入到Excel中。 没有任何理由,除了一种方式让我跟随数据,因为它填充信息的工作表,有没有办法保持当前单元格的焦点强迫工作表滚动(就像点击滚动条上的向下箭头)随着数据录入? 我目前的代码如下:

else if (driver.FindElements(By.XPath("//table[7]/tbody /tr/td[11]")).Count > 0) { activesheet.Range["D" + n].Value = driver.FindElement(By.XPath("//table[7]/tbody/tr/td[11]")).Text; activesheet.Range["A" + n].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); activesheet.Range["B" + n].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); activesheet.Range["C" + n].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); activesheet.Range["D" + n].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); activesheet.Range["E" + n].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); } 

我相信这很简单,我只是无法find这个信息/命令,我也不能确定我的search是否正确或者是否存在。

使用ActiveWindowScrollRow属性。 如果你只是想“击中向下箭头”,你可以增加。

 //app is a valid reference to a Microsoft.Office.Interop.Excel.Application instance app.ActiveWindow.ScrollRow++; 

参考: https : //msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.window.scrollrow.aspx