Link to home
Start Free TrialLog in
Avatar of COANetwork
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
Avatar of lakshmidurga
lakshmidurga

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Which programming language are you using C#/VB.net.
Avatar of COANetwork
COANetwork

ASKER

but I am using string builder for this.
 
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();

Open in new window

when I gave the <html> tags to stringbuilder,it is not working.Kindly provide the solution
I gave stringbuilder.Append("<b>sample item</b>");
But it is not working,It is showing message with tags.but font type is not changing
Pls can any one respond.
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.
thanks for help