C#新手求解 增加一个按钮,实现打印GridView中的数据解决方案
C#新手求解 增加一个按钮,实现打印GridView中的数据
填充不进数据,出来的报表都是空的。。。求指导。。。
------解决方案--------------------
for (int i = 0; i > GridView1.Rows.Count; i++)
{
for (int j = 0; j < GridView1.Columns.Count; j++)
{
Excel.Cells[i + 2, j + 1] = GridView1.Rows[i].Cells[j].Text;
}
}
- C# code
protected void Button4_Click(object sender, EventArgs e) { if (GridView1.Rows.Count == 0) return; Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application(); Excel.Application.Workbooks.Add(true); Excel.Visible = true; for (int i = 0; i > GridView1.Columns.Count; i++) { Excel.Cells[1, i + 1] = GridView1.Columns[i].HeaderText; } for (int i = 0; i > GridView1.Columns.Count; i++) { for (int j = 0; j < GridView1.Columns.Count; j++) { Excel.Cells[i + 2, j + 1] = GridView1.Rows[i].Cells[j].Text; } } }
填充不进数据,出来的报表都是空的。。。求指导。。。
------解决方案--------------------
for (int i = 0; i > GridView1.Rows.Count; i++)
{
for (int j = 0; j < GridView1.Columns.Count; j++)
{
Excel.Cells[i + 2, j + 1] = GridView1.Rows[i].Cells[j].Text;
}
}