2-2 使用Activate方法
this.Application.Worksheets[3].Activate();
this.Application.Worksheets[3].Range["A1:B10"].Activate();
注:此处的代码,可以运行,但是只会选中A1这一个单元格
2-3 使用Goto方法
this.Application.Goto(this.Application.Worksheets[3].Range["A1:B10"], true);
3-1 获得指定行,列中的最后一个非空单元格
Excel.Range rng = this.Range["A65535"].End[Excel.XlDirection.xlUp];
MessageBox.Show("A列中最后一个非空单元格是" + rng.Address[0, 0] + ",行号"
+ rng.Row.ToString() + ",数值" + rng.Text);
4-1 定位单元格
Excel.Range rng = this.UsedRange.SpecialCells(Excel.XlCellType.xlCellTypeFormulas);
rng.Select();
MessageBox.Show("工作表中有公式的单元格为:" + rng.Address);
5-1 查找单元格
Excel.Range rng, Rng;
Rng = this.Range["A:A"];
string strFind = textBox1.Text;
if (strFind.Trim() != string.Empty)
{
rng = Rng.Find(strFind, Rng.Cells[Rng.Cells.Count],
Excel.XlFindLookIn.xlValues,Excel.XlLookAt.xlWhole, Excel.XlSearchOrder.xlByRows,
Excel.XlSearchDirection.xlNext, false);
if (rng != null)
{
this.Application.Goto(rng, true);
}
else
{
MessageBox.Show("没有找到单元格!");
}
}
注:C#中没有InputBox,这里用文本框代替,另,C#中没有with……End with语句.
评论0
最新资源