Here I will explain how you can use C# code to write things to Excel. Certainly, there are several good pre-made plugins available which directly write your output to an Excel file. This is more like learning the old school way of how it was done.
Create a simple Console Application to interop excel dll.

Now, you can paste this code in your class.
  1. class Program
  2. {
  3. static void Main(string[] args)
  4. {
  5. Application xlApp = new Application();
  6. if (xlApp == null)
  7. {
  8. //just to check if we get hold of the excel aplication
  9. return;
  10. }
  11. Workbook xlWorkBook;
  12. Worksheet xlWorkSheet;
  13. object misValue = System.Reflection.Missing.Value;
  14. xlWorkBook = xlApp.Workbooks.Add(misValue);
  15. xlWorkSheet = (Worksheet)xlWorkBook.Worksheets.get_Item(1);
  16. xlWorkSheet.Cells[1, 1] = "Sheet 1 content";
  17. //you can basically do what every you want
  18. xlWorkBook.SaveAs("f:\\csharp-Excel.xls", XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
  19. xlWorkBook.Close(true, misValue, misValue);
  20. xlApp.Quit();
  21. releaseObject(xlWorkSheet);
  22. releaseObject(xlWorkBook);
  23. releaseObject(xlApp);
  24. }
  25. //so that we dont leave any memory leaks
  26. private static void releaseObject(object obj)
  27. {
  28. try
  29. {
  30. System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
  31. obj = null;
  32. }
  33. catch (Exception ex)
  34. {
  35. obj = null;
  36. }
  37. finally
  38. {
  39. GC.Collect();
  40. }
  41. }
  42. }
This will create a file and write the sample text in it. The file won't even be visible. So, everything is done in the background.