public Excel.Workbook Print_into_excel_file2(List <Question> Questions, string surveytable, string meetingtable, string sessiontable, string wstable, List <Meeting> Meetings, List <Atelier> sessionAtelier, List <Atelier> wsAtelier) { int position = 1; int meetingpos = 1; int sessionpos = 1; int wspos = 1; var _excel = new Excel.Application(); var wb = _excel.Workbooks.Add(); try { // var wb = _excel.Workbooks.Add(); var collection = new Microsoft.Office.Interop.Excel.Worksheet[5]; collection[0] = wb.Worksheets.Add(); collection[0].Name = String.Format("Workshop"); collection[1] = wb.Worksheets.Add(); collection[1].Name = String.Format("Session"); collection[2] = wb.Worksheets.Add(); collection[2].Name = String.Format("Meeting"); collection[3] = wb.Worksheets.Add(); collection[3].Name = String.Format("General"); Excel.Worksheet xl_Workshop_Sheet = collection[0]; Excel.Worksheet xl_Session_Sheet = collection[1]; Excel.Worksheet xl_Meeting_Sheet = collection[2]; Excel.Worksheet xl_General_Sheet = collection[3]; //xl_General_Sheet.Cells[1, 1] = "Nombre de participants"; //xl_General_Sheet.Cells[1, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); //xl_General_Sheet.Cells[2, 1] = getNbParticipants(PollId, surveytable); for (int j = 0; j < Questions.Count; j++) { Question q = Questions[j]; if (isPredifinedChoices(q)) { xl_General_Sheet.Cells[position, 1] = q.Label; xl_General_Sheet.Cells[position, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); xl_General_Sheet.Cells[position + 1, 1] = "Nombre de réponses"; xl_General_Sheet.Columns.AutoFit(); int i; int cpt = 0; List <Choice> Choices = new List <Choice>(); Choices = q.Choices; for (i = 0; i < Choices.Count; i++) { int nbreponse = DataExtractionUtils.NumberResponse_GeneralQuestion(surveytable, q.Column, Choices[i].Label); xl_General_Sheet.Cells[position, i + 2] = Choices[i].Label; xl_General_Sheet.Cells[position, i + 2].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); xl_General_Sheet.Columns.AutoFit(); xl_General_Sheet.Cells[position + 1, i + 2] = nbreponse; cpt += nbreponse; } xl_General_Sheet.Cells[position, i + 2] = "Total"; xl_General_Sheet.Cells[position, i + 2].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); xl_General_Sheet.Columns.AutoFit(); xl_General_Sheet.Cells[position + 1, i + 2] = cpt; cpt = 0; position = position + 3; } } for (int d = 0; d <= Meetings.Count - 1; d++) { Meeting meeting = Meetings[d]; string guests = ""; foreach (Person p in meeting.guests) { guests += p.FirstName + "(" + p.CompanyName + ");"; } xl_Meeting_Sheet.Cells[meetingpos, 1] = guests; xl_Meeting_Sheet.Cells[meetingpos, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); xl_Meeting_Sheet.Columns.AutoFit(); int nbquestion = 0; for (int j = 0; j < Questions.Count; j++) { Question q = Questions[j]; if (q.Category.Equals("Meeting")) { drawQuestions(q, meetingpos + 1, xl_Meeting_Sheet, meeting.guests, 0, meetingtable, "", ""); nbquestion++; } } meetingpos = meetingpos + 5 * nbquestion; } for (int d = 0; d <= sessionAtelier.Count - 1; d++) { Atelier session = sessionAtelier[d]; xl_Session_Sheet.Cells[sessionpos, 1] = session.theme; xl_Session_Sheet.Cells[sessionpos, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); xl_Session_Sheet.Columns.AutoFit(); int nbquestion = 0; for (int j = 0; j < Questions.Count; j++) { Question q = Questions[j]; if (q.Category.Equals("Activity")) { drawQuestions(q, sessionpos + 1, xl_Session_Sheet, null, session.id_atelier, "", sessiontable, ""); nbquestion++; } } sessionpos = sessionpos + 5 * nbquestion; } for (int d = 0; d <= wsAtelier.Count - 1; d++) { Atelier workshop = wsAtelier[d]; xl_Workshop_Sheet.Cells[wspos, 1] = workshop.theme; xl_Workshop_Sheet.Cells[wspos, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightGreen); xl_Workshop_Sheet.Columns.AutoFit(); int nbquestion = 0; for (int j = 0; j < Questions.Count; j++) { Question q = Questions[j]; if (q.Category.Equals("Workshop")) { drawQuestions(q, wspos + 1, xl_Workshop_Sheet, null, workshop.id_atelier, "", "", wstable); nbquestion++; } } wspos = wspos + 5 * nbquestion; } wb.Worksheets[5].delete(); } finally { Marshal.ReleaseComObject(_excel); } return(wb); }