private void button3_Click(object sender, EventArgs e) { if (dt.Rows.Count > 0) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); //定义打开的默认文件夹位置 openFileDialog1.Filter = "Excel文件(*.xls,xlsx)|*.xls;*.xlsx"; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { this.label8.Text = openFileDialog1.FileName; ExcelHelpers excelHelpers = new ExcelHelpers(); string path = System.IO.Path.GetDirectoryName(openFileDialog1.FileName); string filename = System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName); string extension = System.IO.Path.GetExtension(openFileDialog1.FileName); string newnfilenames = path + '\\' + filename + DateTime.Now.ToString("yyyyMMddHHmmss") + extension; //MessageBox.Show(newnfilenames); excelHelpers.ExcelInsert(dt, newnfilenames, false, this.label8.Text); } } else { MessageBox.Show("数据不能为空"); } }