Ejemplo n.º 1
0
        public void ExportToExcel()
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Excel 2007 - 2016|*.xlsx";
            sfd.Title  = "选择计算文件";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (File.Exists(sfd.FileName))
                {
                    File.Delete(sfd.FileName);
                }
                try
                {
                    var  exporttoexcel = new ExportCalculationSheet(Piles.ToList());
                    Task task          = Task.Run(() => exporttoexcel.Export(sfd.FileName))
                                         .ContinueWith(t => MessageBox.Show($"文件已保存至{sfd.FileName}", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information), TaskContinuationOptions.OnlyOnRanToCompletion);
                    //MessageBox.Show($"文件已保存至{sfd.FileName}", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString(), "输出错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }