Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lblResult_Click(object sender, EventArgs e)
        {
            //打开改文件
            MyExcel myExcel = new MyExcel(xlsFilePath);

            AppManagement.add(myExcel.open(true));
        }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void showTemplateToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (null == myExcel)
     {
         myExcel = new MyExcel(DownloadExcelTemplate.path);
     }
     AppManagement.add(myExcel.open(true));
 }
Пример #3
0
 /// <summary>
 ///
 /// </summary>
 public int openWithoutAlerts(bool isVisible = false)
 {
     if (!File.Exists(_path))
     {
         MessageBox.Show("此Excel不存在!", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return(0);
     }
     _app               = new Microsoft.Office.Interop.Excel.ApplicationClass();
     _app.Visible       = isVisible;
     _app.DisplayAlerts = false;
     try
     {
         WBook = _app.Workbooks.Open(this._path, 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);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         if (WBook != null)
         {
             WBook.Close(true, _path, Type.Missing);
         }
         //退出excel
         _app.Quit();
         //释放资源
         if (WBook != null)
         {
             System.Runtime.InteropServices.Marshal.ReleaseComObject(WBook);
         }
         System.Runtime.InteropServices.Marshal.ReleaseComObject(_app);
         //调用GC的垃圾回收方法
         GC.Collect();
         GC.WaitForPendingFinalizers();
         return(0);
     }
     _HwndOfApp = _app.Hwnd;
     AppManagement.add(_HwndOfApp);
     return(_app.Hwnd);
 }