Пример #1
0
        /// <summary>
        /// 导出Excel
        /// </summary>
        private void btnExcel_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (!this.isDoing)
            {
                this.isDoing = true;
                SaveFileDialog fileDialog = new SaveFileDialog()
                {
                    Filter = "Excel文件 (*.xlsx)|*.xlsx"
                };
                fileDialog.Title = "请选择保存路径";
                fileDialog.ShowDialog();
                string path = fileDialog.FileName;
                if (!string.IsNullOrEmpty(path))
                {
                    bool result = this.service.ExcportExcel(path, this.cmbExcel.SelectedIndex.ToString(),
                                                            this.dateFrom.SelectedDate, this.dateTo.SelectedDate);
                    if (result)
                    {
                        Message.ShowMessage("导出成功", this);

                        result = Message.ShowConfirmMessage("是否打开Excel文件?", this);

                        if (result)
                        {
                            service.OpenExcel(path);
                        }
                    }
                    else
                    {
                        Message.ShowMessage("导出失败,请检查文件是否被占用", this);
                    }
                }
                this.isDoing = false;
            }
        }