using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
namespace ExcelWorkbook1
{
public partial class Sheet1
{
private void Sheet1_Startup(object sender, System.EventArgs e)
{
}
private void Sheet1_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO 设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InternalStartup()
{
this.button1.Click += new System.EventHandler(this.button1_Click);
this.namedRange1.Change += new Microsoft.Office.Interop.Excel.DocEvents_ChangeEventHandler(this.namedRange1_Change);
this.Shutdown += new System.EventHandler(this.Sheet1_Shutdown);
this.Startup += new System.EventHandler(this.Sheet1_Startup);
}
#endregion
private void button1_Click(object sender, EventArgs e)
{
Excel.Worksheet ws;
int l;
ws = (Excel.Worksheet)Globals.ThisWorkbook.Worksheets["sheet1"];
l = ws.Application.get_Range("A65536", missing).get_End(Excel.XlDirection.xlUp).Row;
MessageBox.Show(l.ToString());
}
2.missing不可缺少;ToString()后面的括号不能少;
3.get_End(Excel.XlDirection.xlUp).Row相对于VBA好啰嗦啊