DataGridView中dgvShow是什么呀?怎么用?
我是想把DataGridView中的数据写到EXCEL中去。 从网上找的程序中用到了dgvShow。程序如下:
private void ToExcel_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Excel.ApplicationClass MyExcel = new
Microsoft.Office.Interop.Excel.ApplicationClass();
MyExcel.Visible = true;
if (MyExcel == null)
{
MessageBox.Show("EXCEL无法启动!", "错误", MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
int rowcount = 0;
int columncount = 0;
MyExcel.Application.Workbooks.Add(true);
columncount = this.dgvShow.ColumnCount;
rowcount = this.dgvShow.RowCount;
for (int m = 1; m < columncount; m++)
{
MyExcel.Cells[1, m] = this.dgvShow.Columns[m-1].HeaderText;//去除dgvShow的编号列
}
for (int i = 0; i < rowcount; i++)
{
for (int j = 1; j < columncount; j++)
{
MyExcel.Cells[i + 2, j] = Convert.ToString(this.dgvShow[j-1, i].Value);
}
}
}
但是VS2008却提示:
错误 1 “graduata_v2.Form1”不包含“dgvShow”的定义,并且找不到可接受类型为“graduata_v2.Form1”的第一个参数的扩展方法“dgvShow”(是否缺少 using 指令或程序集引用?)
不知道什么原因,请大侠指点啊,多谢多谢。