if (dataGridView1.Rows.Count != 0)
{
saveFileDialog1.Filter = "Execl files (*.xls)|*.xls";
saveFileDialog1.FilterIndex = 0;
saveFileDialog1.RestoreDirectory = true;
saveFileDialog1.CreatePrompt = true;
saveFileDialog1.Title = "U09D";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
Stream mystream = saveFileDialog1.OpenFile();
StreamWriter sw = new StreamWriter(mystream, System.Text.Encoding.GetEncoding(-0));
try
{
string str = "";
for (int i = 0; i < dataGridView1.ColumnCount; i++)
{
if (i > 0)
{
str += "/t";
}
str += dataGridView1.Columns[i].HeaderText;
}
sw.WriteLine(str);
for (int j = 0; j < dataGridView1.Rows.Count; j++)
{
string tempstr = "";
for (int K = 0; K < dataGridView1.Columns.Count; K++)
{
if (K > 0)
{
tempstr += "/t";
}
tempstr += dataGridView1.Rows[j].Cells[K].Value.ToString();
}
sw.WriteLine(tempstr);
}
sw.Flush();
sw.Close();
mystream.Close();
}
catch (Exception ee)
{
MessageBox.Show(ee.ToString(), "警告");
}
finally
{
sw.Flush();
sw.Close();
mystream.Close();
}
}
catch (Exception ee)
{
MessageBox.Show(ee.ToString());
}
}
小弟实在看不出以上代码中哪里没实例化T-T