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();
            }
        }
    
    
    
    }
    

      

  • 相关阅读:
    <C#>关于string.Empty & "" & null 的讨论
    c# checked unchecked 关键字 try
    sql2005数据库加锁后解锁
    c#对字符串转义符进行解码
    继承本质论
    javascript中parseInt和Number函数的用法区别
    BIRT 使用说明书
    最后一周
    修改字段
    SQLserver中join
  • 原文地址:https://www.cnblogs.com/2zhyi/p/3640973.html
Copyright © 2011-2022 走看看