您的位置:首页 > 编程语言 > ASP

Refresh Excel (asp.net,C#)

2014-04-02 16:20 344 查看
#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();
}
}

}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: