using Excel = Microsoft.Office.Interop.Excel; using System.Reflection;
try { Excel.Application oXL; Excel._Workbook oWB; Excel._Worksheet oSheet; Excel.Application ThisApplication = new Excel.Application(); string path2 = System.IO.Directory.GetCurrentDirectory(); //obtient le répertoire en cours du programme string path3 = System.IO.Directory.GetCurrentDirectory(); //obtient le répertoire en cours du programme //lance Excel. oXL = new Excel.Application(); oXL.Visible = true; oWB = (Excel._Workbook)(oXL.Workbooks.Add(Missing.Value)); oSheet = (Excel._Worksheet)oWB.ActiveSheet; string cod = dataGridView1.CurrentRow.Cells["actcod"].Value.ToString(); string nom = dataGridView1.CurrentRow.Cells["actnom"].Value.ToString(); string prenom = dataGridView1.CurrentRow.Cells["actpre"].Value.ToString(); //Rajoute le texte dans les tables. oSheet.Cells[1, 1] = nom + " " + prenom; oSheet.Cells[2, 1] = cod; oSheet.Cells[5, 6] = "Voci les acteurs "; oSheet.Cells[6, 6] = "BLABLABLA"; oXL.Visible = true; oXL.UserControl = true; } catch (Exception theException) { String errorMessage; errorMessage = "Error: "; errorMessage = String.Concat(errorMessage, theException.Message); errorMessage = String.Concat(errorMessage, " Line: "); errorMessage = String.Concat(errorMessage, theException.Source); MessageBox.Show(errorMessage, "Error"); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question