Sorry it is not possible to check your code due to the uses of thirdparty librarys. Instead of using closedxml library for export to excel use the Microsoft.Office.Interop library and check.
Code
System.Data.DataTable dt = new System.Data.DataTable("Sub Categories Template");
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)), new DataColumn("Name", typeof(string)), new DataColumn("Country", typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook xlWorkBook = (Microsoft.Office.Interop.Excel.Workbook)xlApp.Workbooks.Add(1); ;
Microsoft.Office.Interop.Excel.Worksheet xlSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.ActiveSheet; ;
object misvalue = System.Reflection.Missing.Value;
for (int i = 0; i < dt.Columns.Count; i++)
{
xlSheet.Cells[1, i + 1] = dt.Columns[i].ColumnName;
}
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
xlSheet.Cells[i + 2, j + 1] = dt.Rows[i][j].ToString().Trim();
}
}
xlWorkBook.SaveAs(@"C:\Users\Downloads\BSDSubCategoriesTemplate_" + DateTime.Now.ToString("dd-MM-yyyy") + ".xlsx",
misvalue, misvalue, misvalue, misvalue, misvalue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, misvalue, misvalue, misvalue, misvalue, misvalue);
xlWorkBook.Close(true, misvalue, misvalue);
xlSheet = null;
xlApp = null;