Advertisement
Guest User

Untitled

a guest
May 6th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. Excel.Workbook xlWorkBook;
  2. Excel.Worksheet xlWorkSheet;
  3. object misValue = System.Reflection.Missing.Value;
  4. xlWorkBook = xlApp.Workbooks.Add(misValue);
  5. xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
  6.  
  7. //Write Column Headers
  8. xlWorkSheet.Cells[1, 1] = "Name";
  9. xlWorkSheet.Cells[1, 2] = "Address";
  10. xlWorkSheet.Cells[1, 3] = "Phone Number";
  11. xlWorkSheet.Cells[1, 4] = "Postal Code";
  12. xlWorkSheet.Cells[1, 5] = "Region";
  13. xlWorkSheet.Cells[1, 6] = "Locality";
  14.  
  15. //Populate cells with participant information
  16. xlWorkSheet.Cells[i + 1, 1] = participantName[i];
  17. xlWorkSheet.Cells[i + 1, 2] = participantAddress[i];
  18. xlWorkSheet.Cells[i + 1, 3] = participantNumber[i];
  19. xlWorkSheet.Cells[i + 1, 4] = participantPostalCode[i];
  20. xlWorkSheet.Cells[i + 1, 5] = participantRegion[i];
  21. xlWorkSheet.Cells[i + 1, 6] = participantLocality[i];
  22.  
  23.  
  24. //Save Workbook and safely close it
  25. xlWorkBook.SaveAs("c:\csharp-Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
  26. xlWorkBook.Close(true, misValue, misValue);
  27. xlApp.Quit();
  28.  
  29. //Release the objects
  30. releaseObject(xlWorkSheet);
  31. releaseObject(xlWorkBook);
  32. releaseObject(xlApp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement