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 27 28 29 30 31 32 33 34 35 36 37 38
|
// déclaration objet excel
Microsoft.Office.Interop.Excel.Application ObjExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook ObjWorkBook;
Microsoft.Office.Interop.Excel.Worksheet ObjWorkSheet;
Range range = null;
// listFic[i] correspond a l'ensemble des fichiers excel listé au préalable
ObjWorkBook = ObjExcel.Workbooks.Open(listFic[i].ToString(), 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);
// on selectionne la feuille
ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBook.Sheets[1];
// on affecte l'objet range a la feuille
// get a range to work with
range = ObjWorkSheet.get_Range("A1", Missing.Value);
// get the end of values to the right (will stop at the first empty cell)
range = range.get_End(XlDirection.xlToRight);
// get the end of values toward the bottom, looking in the last column (will stop at first empty cell)
range = range.get_End(XlDirection.xlDown);
// get the address of the bottom, right cell
string downAddress = range.get_Address(
false, false, XlReferenceStyle.xlA1,
Type.Missing, Type.Missing);
// Get the range, then values from a1
range = ObjWorkSheet.get_Range("A1", downAddress);
// j'utilise une arrayList pour stocker les infos provenant des cellules du fichier excel
ArrayList listInfo = new ArrayList();
listInfo.Add(((Range)range.Cells[39, 3]).Value2.ToString());
listInfo.Add(((Range)range.Cells[41, 3]).Value2.ToString());
listInfo.Add(((Range)range.Cells[43, 3]).Value2.ToString());
listInfo.Add(((Range)range.Cells[37, 9]).Value2.ToString());
listInfo.Add(((Range)range.Cells[41, 9]).Value2.ToString());
listInfo.Add(((Range)range.Cells[45, 3]).Value2.ToString()); |
Partager