1 //// 存储路径弹框选择
2 SaveFileDialog saveDialog = new SaveFileDialog();
3 saveDialog.DefaultExt = "xls";
4 saveDialog.Filter = "Excel文件|*.xls";
5 saveDialog.FileName = output;
6 //saveDialog.ShowDialog();
7 //output = saveDialog.FileName;
8 //if (output.IndexOf(":") < 0) return; //被点了取消
9 //if (output != "")
10 //{
11 try
12 {
13 file = File.OpenWrite(saveDialog.FileName);
14 workbook.Write(file);
15
16 System.Diagnostics.Process.Start("Excel.exe",output);
17 }
18 catch (Exception ex)
19 {
20 MessageBox.Show("导出文件时出错,文件可能正被打开!
" + ex.Message);
21 }
导出dgv中是数据到Excel的具体代码,可见NPOI_winfrom导出Excel表格(一),上面是代码也是在之前的基础上修改的,这里着重:
System.Diagnostics.Process.Start("Excel.exe",output);
output:是保存的此Excel文件的路径