Beispiel #1
0
 private void ExportXls(TabControl tabControl)
 {
   CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
   try
   {
     this.Cursor = Cursors.WaitCursor;
     Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
     Thread.CurrentThread.CurrentCulture.DateTimeFormat = currentCulture.DateTimeFormat;
     Excel excel = new Excel();
     excel.Workbooks.Add();
     Workbook workbook = excel.Workbooks[1];
     WorksheetList worksheets = workbook.Worksheets;
     for (int index = 0; index < tabControl.TabCount; ++index)
     {
       TabPage tabPage = tabControl.TabPages[index];
       switch (tabPage.Text)
       {
         case "Composition":
           IEnumerator enumerator = tabPage.Controls[0].Controls.GetEnumerator();
           try
           {
             while (enumerator.MoveNext())
             {
               Control control = (Control) enumerator.Current;
               worksheets.AddLast();
               Worksheet sheet = worksheets[worksheets.Count - 1];
               sheet.Name = control.Text;
               this.CopyDataToWorksheet(sheet, new ListView[1]
               {
                 control.Controls[0] as ListView
               });
             }
             break;
           }
           finally
           {
             IDisposable disposable = enumerator as IDisposable;
             if (disposable != null)
               disposable.Dispose();
           }
         case "Performance":
           PortfolioPerformance performance = ((PerformanceWindow) tabPage.Controls[0]).Portfolio.Performance;
           worksheets.AddLast();
           Worksheet sheet1 = worksheets[worksheets.Count - 1];
           sheet1.Name = "Performance";
           this.CopyDataToWorksheet(sheet1, performance);
           break;
         case "Correlation Matrix":
         case "Children Statistics":
         case "Statistics":
           Control control1 = tabPage.Controls[0];
           worksheets.AddLast();
           Worksheet sheet2 = worksheets[worksheets.Count - 1];
           sheet2.Name = tabPage.Text;
           this.CopyDataToWorksheet(sheet2, new ListView[1]
           {
             control1.Controls[0] as ListView
           });
           break;
       }
     }
     workbook.Worksheets[1].Activate();
     excel.Visible = true;
   }
   catch (Exception ex)
   {
     int num = (int) MessageBox.Show((IWin32Window) this, string.Format("An error occured while exporting results. Possible, MS Office is not installed.{0}{0}{1}", (object) Environment.NewLine, (object) ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
   }
   finally
   {
     Thread.CurrentThread.CurrentCulture = currentCulture;
     this.Cursor = Cursors.Default;
   }
 }
 private void ExportXls(TabControl tabControl)
 {
     CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
     try
     {
         this.Cursor = Cursors.WaitCursor;
         Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
         Thread.CurrentThread.CurrentCulture.DateTimeFormat = currentCulture.DateTimeFormat;
         Excel excel = new Excel();
         excel.Workbooks.Add();
         Workbook workbook = excel.Workbooks[1];
         WorksheetList worksheets = workbook.Worksheets;
         for (int index = 0; index < tabControl.TabCount; ++index)
         {
             TabPage tabPage = tabControl.TabPages[index];
             Control control = tabPage.Controls[0];
             if (control is ListView)
             {
                 worksheets.AddLast();
                 Worksheet sheet = worksheets[index + 1];
                 sheet.Name = tabPage.Text;
                 this.CopyDataToWorksheet(sheet, new ListView[1]
                 {
       control as ListView
                 });
             }
             else if (control is DataGridView)
             {
                 worksheets.AddLast();
                 Worksheet sheet = worksheets[index + 1];
                 sheet.Name = tabPage.Text;
                 this.CopyDataToWorksheet(sheet, new DataGridView[1]
                 {
       control as DataGridView
                 });
             }
         }
         workbook.Worksheets[1].Activate();
         excel.Visible = true;
     }
     catch (Exception ex)
     {
         int num = (int)MessageBox.Show((IWin32Window)this, string.Format("An error occured while exporting results. Possible, MS Office is not installed.{0}{0}{1}", (object)Environment.NewLine, (object)ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
     }
     finally
     {
         Thread.CurrentThread.CurrentCulture = currentCulture;
         this.Cursor = Cursors.Default;
     }
 }