public void btnExportExcel_Click(object sender, EventArgs e) { string localFilePath = ""; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Excel Files(07版本 *.xlsx)|*.xlsx|(03版本 *.xls)|*.xls|所有文件(*.*)|*.*"; sfd.FilterIndex = 1; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { localFilePath = sfd.FileName.ToString(); //获得文件路径 } if (localFilePath == "") { MessageBox.Show("未选择Excel文件"); return; } NopiExcel.TableToExcel(dgv, localFilePath); }
public void ExpToExcel() { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { string localFilePath = ""; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Excel Files(07版本 *.xlsx)|*.xlsx|(03版本 *.xls)|*.xls|所有文件(*.*)|*.*"; sfd.FilterIndex = 1; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == DialogResult.OK) { localFilePath = sfd.FileName.ToString(); //获得文件路径 } if (localFilePath == "") { MessageBox.Show("未选择Excel文件"); return; } NopiExcel.TableToExcel(dgv, localFilePath); } }