來自收藏

//create a new ExcelPackage
using (ExcelPackage excelPackage = new ExcelPackage())
{
    //create a WorkSheet
    ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Sheet 1");

    //create a new list with books
    List<Book> books = new List<Book>();
    
    //add some books to the list
    for (int i = 0; i < 10; i++)
    {
        Book b = new Book();

        b.id = i;
        b.name = "Name " + i;
        b.category = "Category " + i;
        b.date = DateTime.Now.AddDays(i).AddHours(i);

        books.Add(b);
    }    

    //add all the content from the List<Book> collection, starting at cell A1
    worksheet.Cells["A1"].LoadFromCollection(books);
}