Dưới đây là một ví dụ về làm thế nào để mở một file Excel sử dụng Excel-Interop, và xử lý đúng thẩm (nguồn: google)
Application ExcelObj = new Application();
Workbook WB = ExcelObj.Workbooks.Open(fileName,
0, true, 5, "", "", true, XlPlatform.xlWindows, "\t",
false, false, 0, true, false, false);
Sheets sheets = WB.Worksheets;
Worksheet WS = (Worksheet)sheets.get_Item(1);
Range excelRange = WS.UsedRange;
... (DO STUFF?)
// Get rid of everything - close Excel
while (Marshal.ReleaseComObject(WB) > 0) { }
WB = null;
while (Marshal.ReleaseComObject(sheets) > 0) { }
sheets = null;
while (Marshal.ReleaseComObject(WS) > 0) { }
WS = null;
while (Marshal.ReleaseComObject(excelRange) > 0) { }
excelRange = null;
GC();
ExcelObj.Quit();
while (Marshal.ReleaseComObject(ExcelObj) > 0) { }
ExcelObj = null;
GC();
public static void GC()
{
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
}
bạn có thể bắt đầu nói với chúng ta như thế nào bạn tạo/mở excel ? hiển thị một số mã xin vui lòng –
Bạn cần PID để làm gì? bạn có thể tự giải phóng các đối tượng Com – Shai