本文整理汇总了C#中Microsoft.Office.Interop.Excel.Quit方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Excel.Quit方法的具体用法?C# Microsoft.Office.Interop.Excel.Quit怎么用?C# Microsoft.Office.Interop.Excel.Quit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Excel
的用法示例。
在下文中一共展示了Microsoft.Office.Interop.Excel.Quit方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseExcel
// closes Excel
public static void CloseExcel(Excel.Application xlApp, Excel.Workbook wb)
{
// Close Excel
object misValue = System.Reflection.Missing.Value;
wb.Close(false, misValue, misValue);
xlApp.Quit();
}
示例2: ReleaseExcel
protected void ReleaseExcel(ref MSOffice.Application excelApp, ref MSOffice.Workbook excelBook, ref MSOffice.Worksheet excelSheet)
{
try
{
excelBook.Close(false, null, null);
excelApp.Quit();
GC.Collect();
IntPtr ptr = new IntPtr(excelApp.Hwnd);
int pid = 0;
GetWindowThreadProcessId(ptr, out pid);
System.Diagnostics.Process proc = System.Diagnostics.Process.GetProcessById(pid);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)excelApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)excelBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject((object)excelSheet);
excelApp = null;
excelBook = null;
excelSheet = null;
//最后尝试结束进程,出错表示已销毁
try
{ proc.Kill(); }
catch (Exception) { }
}
catch (Exception ex)
{
throw ex;
}
}
示例3: Dispose
/// <summary>
/// 释放内存
/// </summary>
public void Dispose(Excel._Worksheet CurSheet, Excel._Workbook CurBook, Excel._Application CurExcel)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(CurSheet);
CurSheet = null;
CurBook.Close(false, mValue, mValue);
System.Runtime.InteropServices.Marshal.ReleaseComObject(CurBook);
CurBook = null;
CurExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(CurExcel);
CurExcel = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
catch (System.Exception)
{
// Response.Write("在释放Excel内存空间时发生了一个错误:" + ex);
}
finally
{
foreach (System.Diagnostics.Process pro in System.Diagnostics.Process.GetProcessesByName("Excel"))
//if (pro.StartTime < DateTime.Now)
pro.Kill();
}
System.GC.SuppressFinalize(this);
}
示例4: CloseAndReleaseExcelObjects
private static void CloseAndReleaseExcelObjects(Excel.Application xlApp, Excel.Workbook xlworkBook, Excel.Worksheet xlWorksheet)
{
xlworkBook.Close(false, null, null);
xlApp.Quit();
ReleaseObject(xlWorksheet);
ReleaseObject(xlworkBook);
ReleaseObject(xlApp);
}
示例5: ExcelDispose
/// <summary>
/// 저장및 메모리 해제
/// </summary>
/// <param name="excelApp"></param>
/// <param name="wb"></param>
/// <param name="workSheet"></param>
public static void ExcelDispose(Excel.Application excelApp, Excel.Workbook wb, Excel._Worksheet workSheet)
{
wb.SaveAs(@"C:\users\user\Desktop\수강신청시간표", Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
wb.Close(Type.Missing, Type.Missing, Type.Missing);
excelApp.Quit();
releaseObject(excelApp);
releaseObject(workSheet);
releaseObject(wb);
}
示例6: release_excel_app
private void release_excel_app(ref MSExcel.Application excelApp)
{
excelApp.Workbooks[1].Close();
excelApp.Quit();
if (excelApp != null)
{
int lpdwProcessID;
GetWindowThreadProcessId(new IntPtr(excelApp.Hwnd), out lpdwProcessID);
System.Diagnostics.Process.GetProcessById(lpdwProcessID).Kill();
}
}
示例7: ExcelQuit
/// <summary>
/// Close Excel workbook, quit excel and wait until finished
/// </summary>
/// <param name="app">Excel handle to quit</param>
/// <param name="wb">Excel workbook to close</param>
private static void ExcelQuit(Excel.Application app, Excel.Workbook wb)
{
wb.Close(SaveChanges: false);
app.Quit();
while (Marshal.ReleaseComObject(app) != 0)
{
}
app = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
示例8: SaveExcel
private void SaveExcel(string file, MSExcel.Application excel, MSExcel.Workbook wbook)
{
try
{
File.Delete(file);
}
catch //(Exception ex)
{
wbook.Close(false);
excel.Quit();
return;
}
try
{
wbook.SaveAs(file, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, MSExcel.XlSaveAsAccessMode.xlExclusive);
}
catch//(Exception ex)
{
}
wbook.Close(false);
excel.Quit();
}
示例9: ConvertToXlsx
public static string ConvertToXlsx(string filePath, Excel.Application excel = null)
{
excel = excel ?? CreateExcel();
var workbook = excel.Workbooks.Open(filePath, UpdateLinks: false, ReadOnly: true);
var path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
workbook.SaveAs(path, FileFormat: Excel.XlFileFormat.xlOpenXMLWorkbook,
AccessMode: Excel.XlSaveAsAccessMode.xlNoChange);
workbook.Close(false);
excel.Quit();
return path;
}