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 39 40 41 42 43
| private void btnExcel_Click(object sender, EventArgs e)
{
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;
//Start exccel
oXL = new Excel.Application();
oXL.Visible = true;
//new workbook
oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel.Worksheet)oWB.ActiveSheet;
//Table header nomDesChamps
int i = 1;
foreach (var item in nomDesChamps)
{
oSheet.Cells[1, i] = item;
i++;
}
//Format de A1 a D1
oSheet.get_Range("A1", "Z1").Font.Bold = true;
oSheet.get_Range("A1", "Z1").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
oSheet.get_Range("A1", "Z1").Cells.EntireColumn.AutoFit();
//Création du tableau
int t = 0;
string[,] answer = new string[26,reslutatRequete.Count];
foreach (var item in reslutatRequete)
{
answer[t, 0] = item;
t++;
}
//fill de A2 a
oSheet.get_Range("A2", "Z2").Value2 = answer;
//Sur que c'est visible et donne le controle
oXL.Visible = true;
oXL.UserControl = true;
} |
Partager