BKM
BKM

Reputation: 186

while exporting datatable to excel the decimal values such as 5 then 5.1,5.2 in the columns creates a new whole line and makes the excel sheet messy

My column has values like 2 then 2.1 then 2.2 but i want all that in one cell only but instead i am getting whole new line for the increase in series. I cannot use any 3rd party library as i am instructed not to so anyone know how to solve the issue with this code note : cannot use gridview nor any 3rd party tools and this is the only other code which worked fine.

        DataTable dt = ExcelDS.Tables[0];
        string attachment = "attachment; filename=AuditAnalysicReport.xls";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/vnd.ms-excel";
        string tab = "";
        foreach (DataColumn dc in dt.Columns)
        {
            Response.Write(tab + dc.ColumnName);
            tab = "\t";
        }
        Response.Write("\n");
        int i;
        foreach (DataRow dr in dt.Rows)
        {
            tab = "";
            for (i = 0; i < dt.Columns.Count; i++)
            {
                Response.Write(tab + dr[i].ToString());
                tab = "\t";
            }
            Response.Write("\n");
        }
        Response.End();

Upvotes: 0

Views: 295

Answers (1)

pranit
pranit

Reputation: 51

convert the float value to string while returning from sql

CONVERT(nvarchar,ColumnName) as ColumnName

then it won't create new whole line

Upvotes: 3

Related Questions