public void button_export(object sender, RoutedEventArgs e) { string path = string.Empty; var openFileDialog = new Microsoft.Win32.OpenFileDialog() { Filter = "Files (*.xlsx*)|*.xls*"//如果需要筛选txt文件("Files (*.txt)|*.txt") }; var result = openFileDialog.ShowDialog(); if (result == true) { path = openFileDialog.FileName; } if (path.Length > 0) { OtherDAL dAL = new OtherDAL(); Console.WriteLine(path); exportExcel exp = new exportExcel(); exp.export(dAL.getOtherData(), path, "Other"); MessageBox.Show("导出完成"); } }