23-1 使用For遍历工作表
int wkCount = this.Application.Worksheets.Count;
string s = string.Empty;
for (int i = 1; i <= wkCount; i++)
{
s = s + this.Application.Worksheets[i].Name + "\n";
}
MessageBox.Show("工作簿中含有以下工作表:" + "\n" + s);
23-2 使用ForEach语句
string s = string.Empty;
foreach (Excel.Worksheet wk in this.Application.Worksheets)
{
s = s + wk.Name + "\n";
}
MessageBox.Show("工作簿中含有以下工作表:" + "\n" + s);
24-1 在工作表中向下翻页
Excel.Sheets shs=Globals.ThisWorkbook.Worksheets;
Excel.Worksheet wkThis = shs.Application.ActiveSheet;
Excel.Worksheet wkNext;
int wkIndex = wkThis.Index;
int wkCount = shs.Count;
if (wkIndex < wkCount)
{
wkNext = (Excel.Worksheet)wkThis.Next;
wkNext.Select();
}
27-1 自动建立工作表目录
int i = this.Application.Worksheets.Count;
for (int n = 1; n <= i; n++)
{
this.Cells[n+1, 1].Value = this.Application.Worksheets[n].Name;
}
27-1 建立工作表链接
int m = this.Application.Worksheets.Count;
if (Target.Count == 1)
{
if (Target.Column==1)
{
if (Target.Row>1 && Target.Row<=(m+1))
{
this.Application.Sheets[Target.Value].Select();
}
}
}