COANetwork
asked on
How to give styles to .CSV file while exporting to .CSV
Could any one pls explaing how to give styles(like make font bold) while exporting gridview to .CSV in Asp.Net
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Which programming language are you using C#/VB.net.
ASKER
but I am using string builder for this.
pls check my code below and kindly advise.
pls check my code below and kindly advise.
System.Text.StringBuilder sbCsv=new StringBuilder();
DataSet ds = (DataSet)Session[this.ReportDSID];
DataTable dtTemp = new DataTable();
dtTemp = ds.Tables[0];
int colcount = dtTemp.Columns.Count;
int rowcount = dtTemp.Rows.Count;
sbCsv.Append("<html><b>Downloaded time</b></html>");
for (int i = 0; i < colcount; i++)
{
sbCsv.Append(this.ReportGridView.Columns[i]);
if (i < colcount - 1)
{
sbCsv.Append(",");
}
}
for (int intRow = 0; intRow < rowcount; intRow++)
{
StringBuilder sbRow=new StringBuilder();
for (int intCol = 0; intCol < colcount; intCol++)
{
if (sbRow.Length > 0)
{
sbRow.Append(",");
}
sbRow.Append(_EscapeCsvField(dtTemp.Rows[intRow][intCol].ToString()));
}
if(sbCsv.Length > 0)
{
sbCsv.Append("\n");
}
sbCsv.Append(sbRow.ToString());
}
Response.Clear();
Response.ContentType = "application/excel";
Response.BinaryWrite(System.Text.ASCIIEncoding.ASCII.GetBytes(sbCsv.ToString()));
Response.AppendHeader("content-disposition", "attachment; filename=wtf.csv");
Response.End();
ASKER
when I gave the <html> tags to stringbuilder,it is not working.Kindly provide the solution
ASKER
I gave stringbuilder.Append("<b>s ample item</b>");
But it is not working,It is showing message with tags.but font type is not changing
But it is not working,It is showing message with tags.but font type is not changing
ASKER
Pls can any one respond.
ASKER
The above link mentioned that we need to use literal control.But how to give styles to literal control.Could you pld provide the code for this.
ASKER
thanks for help