1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
//Initialisation
private Microsoft.Office.Interop.Excel._Application docExcel;
private Microsoft.Office.Interop.Excel._Workbook workbooksExcel;
private Microsoft.Office.Interop.Excel._Worksheet worksheetExcel;
docExcel = new Microsoft.Office.Interop.Excel.Application();
docExcel.Visible = visible;
docExcel.DisplayAlerts = false;
//Ouverture
workbooksExcel = docExcel.Workbooks.Open(@"C:\monFicher.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
worksheetExcel = (_Worksheet)workbooksExcel.ActiveSheet;
//Ecriture
((Range)worksheetExcel.Cells["1", "A"]).Value2 = "aa";
((Range)worksheetExcel.Cells["1", "B"]).Value2 = "bb";
//Fermeture
workbooksExcel.Close(false, Type.Missing, Type.Missing);
docExcel.Application.DisplayAlerts = true;
docExcel.Application.Quit();
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(worksheetExcel) != 0) { }
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(workbooksExcel) != 0) { }
while (System.Runtime.InteropServices.Marshal.ReleaseComObject(docExcel) != 0) { }
GC.Collect();
GC.WaitForPendingFinalizers(); |
Partager