using Excel.Export.Data; using ExcelExport.Base; using ExcelExport.Export; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace ExcelExport.UI { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { private DataTable _dataTable; public MainWindow() { InitializeComponent(); Loaded += MainWindow_Loaded; exportBtn.Click += ExportBtn_Click; } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { _dataTable = new XmlData().GetTableData("国际数据主要国家(地区)年度数据.xml"); if (_dataTable == null) { MessageBox.Show("加载数据失败!"); return; } this.Title = _dataTable.TableName; DataView dv = new DataView(_dataTable); this.dt.ItemsSource = dv; } private void ExportBtn_Click(object sender, RoutedEventArgs e) { if (_dataTable is null) { MessageBox.Show("没有找到要导出的数据"); return; } IExport export = null; string exportType = this.combox.SelectionBoxItem.ToString(); switch (exportType) { case "NPOI": export = new NPOIExport(); break; case "EPPlus": export = new EPPlusExport(); break; } if (export is null) { MessageBox.Show("没有找到要导出的方法"); return; } bool flag = export.Export(_dataTable, AppDomain.CurrentDomain.BaseDirectory + _dataTable.TableName + "_" + exportType + ".xlsx"); MessageBox.Show(flag ? "导出成功" : "导出失败"); } } }