hi all my requirement is like download an excel sheet with header when i click on button
so its working but header is not in bold so i want to change header any body can suggest me where to change in my code below is my code
this is my controller
public void ExportClientsListToCSV()
{
StringWriter sw = new StringWriter();
sw.WriteLine("\"User Name\",\"In Time\",\"Out Time\",\"Client Info\",\"User Role\",\"Activity\"");
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=User_Track.csv");
Response.ContentType = "text/csv";
var abc = TempData["test"];
IEnumerable<PAN_LOGINTRK> test = abc as IEnumerable<PAN_LOGINTRK>;
foreach (var line in test)
{
var role = "";
if (line.userrole == 1)
{
role = "CSAdmin";
}
else if (line.userrole == 2)
{
role = "Buyer";
}
else if (line.userrole == 3)
{
role = "Supervisor";
}
else if (line.userrole == 4)
{
role = "OrgAdmin";
}
sw.WriteLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\"",
line.username,
line.Intime,
line.Outtime,
"Client IP: "+line.ClientIP+" Client XIP: "+line.ClientXIP+" Client Agent: "+line.ClinetAgent,
role,
line.Activity));
}
Response.Write(sw.ToString());
Response.End();
}
in view i have written like
function Export() {
var ExportAction = '@Url.RouteUrl("Default", new RouteValueDictionary(new { action = "ExportClientsListToCSV", controller = "UserTrack" }), "http", ConfigurationManager.AppSettings["ContextPath"])'
location.href = ExportAction;
}
What I have tried:
this is my controller
public void ExportClientsListToCSV()
{
StringWriter sw = new StringWriter();
sw.WriteLine("\"User Name\",\"In Time\",\"Out Time\",\"Client Info\",\"User Role\",\"Activity\"");
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=User_Track.csv");
Response.ContentType = "text/csv";
var abc = TempData["test"];
IEnumerable<PAN_LOGINTRK> test = abc as IEnumerable<PAN_LOGINTRK>;
foreach (var line in test)
{
var role = "";
if (line.userrole == 1)
{
role = "CSAdmin";
}
else if (line.userrole == 2)
{
role = "Buyer";
}
else if (line.userrole == 3)
{
role = "Supervisor";
}
else if (line.userrole == 4)
{
role = "OrgAdmin";
}
sw.WriteLine(string.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\",\"{5}\"",
line.username,
line.Intime,
line.Outtime,
"Client IP: "+line.ClientIP+" Client XIP: "+line.ClientXIP+" Client Agent: "+line.ClinetAgent,
role,
line.Activity));
}
Response.Write(sw.ToString());
Response.End();
}
in view i have written like
function Export() {
var ExportAction = '@Url.RouteUrl("Default", new RouteValueDictionary(new { action = "ExportClientsListToCSV", controller = "UserTrack" }), "http", ConfigurationManager.AppSettings["ContextPath"])'
location.href = ExportAction;
}