zoukankan      html  css  js  c++  java
  • Refresh Excel (asp.net,C#)

    #region NameSpace
    using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Web.UI.WebControls;
    using System.Transactions;
    using VAU.Dao;
    using VAU.Dto;
    using VAU.Domain;
    using VAU.EnumType;
    using VAU.Dao.NHibernate;
    using System.Web.UI;
    using Excel = Microsoft.Office.Interop.Excel;
    using System.Configuration;
    using System.IO;
    using System.Diagnostics;
    
    #endregion
    
    public partial class Pages_AtAGlanceReport_BookingView : PageBase
    {
    
        public void RefreshExcel(string execelLocation)
        {
            try
            {
                object _missingValue = System.Reflection.Missing.Value;
                Excel.Application excel = new Excel.Application();
                excel.DisplayAlerts = false;
                Excel.Workbook theWorkbook = excel.Workbooks.Open(execelLocation, _missingValue, false, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue, _missingValue);
    
                lock (theWorkbook)
                {
                    theWorkbook.RefreshAll();
                }
    
                System.Threading.Thread.Sleep(5 * 1000);// Make sure correct save 
    
                theWorkbook.Save();
                theWorkbook.Close();
                excel.Quit();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
    
    
    
    }
    

      

  • 相关阅读:
    【poj2761】 Feed the dogs
    【bzoj1086】 scoi2005—王室联邦
    学堂在线
    【bzoj3757】 苹果树
    【uoj58】 WC2013—糖果公园
    博弈论学习笔记
    【poj2960】 S-Nim
    【poj2234】 Matches Game
    【poj1740】 A New Stone Game
    【bzoj1853】 Scoi2010—幸运数字
  • 原文地址:https://www.cnblogs.com/2zhyi/p/3640973.html
Copyright © 2011-2022 走看看