コード例 #1
0
        public void Dispose()
        {
            try
            {
                if (mBook != null)
                {
                    mBook.Close(false, MISSING, MISSING);
                    mBook = null;
                }
            }
            catch {}

            try
            {
                if (mSheet != null)
                {
                    mSheet = null;
                }
            }
            catch {}

            try
            {
                if (mExcelApp != null)
                {
                    mExcelApp.Quit();
                    mExcelApp = null;
                }
            }
            catch {}
        }
コード例 #2
0
        //Oluşturulan veri seti excell yazılır.
        public void exceleKaydet(int veriCount)
        {
            try
            {
                Microsoft.Office.Interop.Excel.Application xlOrn = new Microsoft.Office.Interop.Excel.Application();

                Microsoft.Office.Interop.Excel.Workbook wb = xlOrn.Workbooks.Add(Microsoft.Office.Interop.Excel.XlSheetType.xlWorksheet);

                Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)xlOrn.ActiveSheet;


                for (int i = 0; i < islemler.feature.Count; i++)
                {
                    ws.Cells[1, i + 1] = islemler.feature.ElementAt(i);
                    for (int j = 0; j < veriCount; j++)
                    {
                        ws.Cells[j + 2, i + 1] = islemler.dataNorm.ElementAt((i * veriCount) + j);
                    }
                }
                string path = Application.StartupPath.ToString() + "\\data" + islemler.rastgele.Next(1, 100) + ".xlsx";
                wb.SaveAs(path, Excel.XlFileFormat.xlWorkbookNormal);
                wb.Close(true);


                MessageBox.Show("Excel dosyası " + path + " komununda oluşturuldu! \nDoğrusal regresyon analizi sonucu ise form ekranın da gösterilmiştir.");
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #3
0
        /// <summary>
        /// Open Excel Workbook
        /// set CurrentWorkbook to received-workbook
        /// EXCEPTION: throw FileNotFoundException if error
        /// </summary>
        /// <param name="pstrWorkbookToOpen">Full path of Workbook to Open</param>
        public void OpenWorkbook(string pstrWorkbookToOpen)
        {
            if (!File.Exists(pstrWorkbookToOpen))               // file not exist
            {
                throw new FileNotFoundException(pstrWorkbookToOpen);
            }

            /// clear all atribbute on Working Book
            System.IO.File.SetAttributes(pstrWorkbookToOpen, FileAttributes.Archive);

            mBook = mExcelApp.Workbooks.Open(pstrWorkbookToOpen,
                                             Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

            mExcelApp.ScreenUpdating = false;
            mExcelApp.Visible        = false;
            mExcelApp.DisplayAlerts  = false;
        }
コード例 #4
0
        /// <summary>
        /// Save the Current working workbook
        /// CLose the Current working workbook
        /// Quit the Excel Interop process
        ///
        /// After calling this function, you should NOT use this Builder ANYMORE
        /// </summary>
        public void CloseWorkbook()
        {
            mExcelApp.ScreenUpdating = true;
            mExcelApp.Visible        = false;
            mExcelApp.DisplayAlerts  = false;

            mBook.Save();
            mBook.Close(Type.Missing, Type.Missing, Type.Missing);
            mSheet = null;
            mBook  = null;

            if (mExcelApp != null)
            {
                mExcelApp.Quit();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(mExcelApp);
                mExcelApp = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }