using OfficeOpenXml; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Epplus_Poc { class Program { static void Main(string[] args) { ListcodeDetails = PopulateCodeDetails(); FileInfo fileInfo = new FileInfo(@"C:\Temp\file.xlsx"); using (ExcelPackage excelPackage = new ExcelPackage(fileInfo)) { var workSheet = GetWorkSheet(excelPackage, 0); var workSheet1 = GetWorkSheet(excelPackage,1); var workSheet2= GetWorkSheet(excelPackage,2); var workSheet3= GetWorkSheet(excelPackage,3); var workSheet4 = GetWorkSheet(excelPackage,4); workSheet.Cells["B2"].LoadFromCollection(codeDetails, false, OfficeOpenXml.Table.TableStyles.Medium1); workSheet1.Cells["B2"].LoadFromCollection(codeDetails, false, OfficeOpenXml.Table.TableStyles.Medium1); workSheet2.Cells["B2"].LoadFromCollection(codeDetails, false, OfficeOpenXml.Table.TableStyles.Medium1); workSheet3.Cells["B2"].LoadFromCollection(codeDetails, false, OfficeOpenXml.Table.TableStyles.Medium1); workSheet4.Cells["B2"].LoadFromCollection(codeDetails, false, OfficeOpenXml.Table.TableStyles.Medium1); excelPackage.Save(); } } static ExcelWorksheet GetWorkSheet(ExcelPackage excelPackage, int count) { var workSheet = excelPackage.Workbook.Worksheets.Add("Content - "+count); workSheet.View.ShowGridLines = false; workSheet.Cells["B1"].Value = "Code"; workSheet.Cells["C1"].Value = "Time"; workSheet.Cells["D1"].Value = "Date"; workSheet.Cells["B1:D1"].Style.Font.Bold = true; return workSheet; } public static List PopulateCodeDetails() { List codeDetails = new List (); Random random = new Random(); for(int i=1; i<=1000000; i++) { CodeDetail codeDetail = new CodeDetail(); codeDetail.Code = random.Next(12324343).ToString(); codeDetail.Time = DateTime.Now.ToShortTimeString(); codeDetail.Date = DateTime.Now.ToShortDateString(); codeDetails.Add(codeDetail); } return codeDetails; } } public class CodeDetail { public string Code { get; set; } public string Time { get; set; } public string Date { get; set; } } }
Share this page on
6
People Like(s) This Page
Permalink
comments powered by Disqus