发布时间:2019-06-21编辑:佚名阅读(2344)
private void test(string filePath) { try { Microsoft.Office.Interop.Excel.Application ThisApplication = new Microsoft.Office.Interop.Excel.Application(); var ThisWorkbook = ThisApplication.Workbooks.Open(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); ThisApplication.DisplayAlerts = false; var xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)ThisWorkbook.Worksheets["sheet1"]; Microsoft.Office.Interop.Excel.Range range = xlSheet.get_Range("P1", Type.Missing); Microsoft.Office.Interop.Excel.Range range1 = xlSheet.get_Range("C6", Type.Missing); range.Copy(range1); ThisWorkbook.Save();//.SaveAs(filePath, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange,Type.Missing, Type.Missing, Type.Missing, Type.Missing); ThisWorkbook.Close(); if (ThisWorkbook != null) { ThisWorkbook.Close(true, Type.Missing, Type.Missing); ThisWorkbook = null; } if (ThisApplication != null) { ThisApplication.Quit(); KillSpecialExcel(ThisApplication); ThisApplication = null; } } catch(Exception ex) { } finally { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); GC.WaitForPendingFinalizers(); } }
上一篇:C#操作Word总结
下一篇:红警2主动攻击
0人
0人
0人
0人