예제 #1
0
파일: Constant.cs 프로젝트: Strongc/sencond
        public static void ExportGrid2Excel(System.Windows.Forms.Form Form,
            Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ExcelExporter,
            Infragistics.Win.UltraWinGrid.UltraGrid Grid)
        {
            Cursor oldCursor = Form.Cursor;

            Form.Cursor = Cursors.WaitCursor;

            if (Constant.WaitingForm == null)
            {
                Constant.WaitingForm = new WaitingForm();
            }

            Constant.WaitingForm.ShowToUser = true;
            Constant.WaitingForm.Show();
            Constant.WaitingForm.Update();

            try
            {
                if (!System.IO.Directory.Exists(System.Environment.CurrentDirectory + "\\temp"))
                {
                    System.IO.Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\temp");
                }

                string StrfileName = string.Format(System.Environment.CurrentDirectory + "\\temp\\" + Form.Text + ".xls");
                ExcelExporter.Export(Grid, StrfileName);

                ProcessStartInfo p = new ProcessStartInfo(StrfileName);
                p.WorkingDirectory = Path.GetDirectoryName(StrfileName);
                Process.Start(p);

                Form.Cursor = oldCursor;
                Constant.WaitingForm.ShowToUser = false;
                Constant.WaitingForm.Close();
            }
            catch (Exception ex)
            {
                Form.Cursor = oldCursor;
                Constant.WaitingForm.ShowToUser = false;
                Constant.WaitingForm.Close();
                MessageBox.Show(ex.Message);
            }
        }