public bool ExportDataGridView(DataGridView gridView, bool isShowExcele)
{
string strcon = "Server=2012-1112-1313\CITADEL;
Database=hetong;Uid='sa';pwd='000000'";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
string strcount = "select * from Aluru where 名?称?= '" +
textBox4.Text + "'";
SqlDataAdapter myDataAdapter = new SqlDataAdapter(strcount,
conn);
DataSet dataset = new DataSet();
myDataAdapter.Fill(dataset); //这a句?跟¨²下?面?的Ì?顺3序¨°不?能¨¹
颠Ì?倒Ì1
dataGridView1.DataSource = dataset.Tables[0];//将?数ºy据Y显?示º?
在¨²dataGridView控?件t
if (gridView.Rows.Count == 0)
return false;
//创ä¡ä建¡§Excel对?象¨®
Excel.Application excel = new Excel.Application();
excel.Application.Workbooks.Add(true);
excel.Visible = isShowExcele;
//生¦¨²成¨¦字Á?段?的Ì?名?称?
for (int i = 0; i < gridView.ColumnCount; i++)
{
excel.Cells[1, i + 1] = gridView.Columns[i].HeaderText;
}
//填¬?充?数ºy据Y
for (int i = 0; i < gridView.RowCount - 1; i++)
{
for (int j = 0; j < gridView.ColumnCount; j++)
{
if (gridView.Rows[i].Cells[j].ValueType ==
typeof(string))
{
excel.Cells[i + 2, j + 1] =
gridView.Rows[i].Cells[j].Value;
}
else
{
excel.Cells[i + 2, j + 1] =
gridView.Rows[i].Cells[j].Value.ToString();
}
}
}
return true;
}
private void button6_Click(object sender, EventArgs e)