01.
using
(var package =
new
ExcelPackage())
02.
{
03.
var workbook = package.Workbook;
04.
05.
06.
var worksheet = workbook.Worksheets.Add(
"Sheet1"
);
07.
08.
worksheet.Cells[
"A1"
].Value =
"ThaiCreate.Com"
;
09.
worksheet.Cells[
"A1"
].Style.Font.Bold =
true
;
10.
worksheet.Cells[
"A1"
].Style.Font.Color.SetColor(System.Drawing.Color.Red);
11.
12.
worksheet.Cells[
"B3"
].Value =
"2017"
;
13.
worksheet.Cells[
"B3"
].Style.Font.Size = 20;
14.
15.
worksheet.Column(5).Width = 50;
16.
worksheet.Cells[
"E5"
].Value =
"New Member"
;
17.
worksheet.Cells[
"E5"
].Style.Font.Size = 12;
18.
worksheet.Cells[
"E5"
].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right;
19.
20.
using
(ExcelRange range = worksheet.Cells[
"A8:E9"
])
21.
{
22.
range.Merge =
true
;
23.
range.Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Medium, System.Drawing.Color.Black);
24.
range.Value =
"Sawatdee ThaiCreate.Com"
;
25.
range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
26.
range.Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center;
27.
range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
28.
range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
29.
range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
30.
range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
31.
}
32.
33.
package.SaveAs(
new
FileInfo(Server.MapPath(@
"Xls/myExcel.xlsx"
)));
34.
}