using
System;
using
System.IO;
using
OfficeOpenXml;
using
OfficeOpenXml.Style;
class
Program
{
static
void
Main(
string
[] args)
{
var
Articles =
new
[]
{
new
{
Id =
"101"
, Name =
"C++"
},
new
{
Id =
"102"
, Name =
"Python"
},
new
{
Id =
"103"
, Name =
"Java Script"
},
new
{
Id =
"104"
, Name =
"GO"
},
new
{
Id =
"105"
, Name =
"Java"
},
new
{
Id =
"106"
, Name =
"C#"
}
};
ExcelPackage excel =
new
ExcelPackage();
var
workSheet = excel.Workbook.Worksheets.Add(
"Sheet1"
);
workSheet.TabColor = System.Drawing.Color.Black;
workSheet.DefaultRowHeight = 12;
workSheet.Row(1).Height = 20;
workSheet.Row(1).Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
workSheet.Row(1).Style.Font.Bold =
true
;
workSheet.Cells[1, 1].Value =
"S.No"
;
workSheet.Cells[1, 2].Value =
"Id"
;
workSheet.Cells[1, 3].Value =
"Name"
;
int
recordIndex = 2;
foreach
(
var
article
in
Articles)
{
workSheet.Cells[recordIndex, 1].Value = (recordIndex - 1).ToString();
workSheet.Cells[recordIndex, 2].Value = article.Id;
workSheet.Cells[recordIndex, 3].Value = article.Name;
recordIndex++;
}
workSheet.Column(1).AutoFit();
workSheet.Column(2).AutoFit();
workSheet.Column(3).AutoFit();
string
p_strPath =
"H:\\geeksforgeeks.xlsx"
;
if
(File.Exists(p_strPath))
File.Delete(p_strPath);
FileStream objFileStrm = File.Create(p_strPath);
objFileStrm.Close();
File.WriteAllBytes(p_strPath, excel.GetAsByteArray());
excel.Dispose();
Console.ReadKey();
}
}