In our application we have a .net report with multiple columns, out of which one column is “Total $ Amount”. When in .net report, the cells under this column displays values like 123.00. Also the report has a button to export this report to excel. After this export, the value in excel displays “123” removing the trailing zeros from the amount.
Now the requirement is to have full string with trailing zeros in the excel report a well. Does anyone in this community came across this scenario?
Also for more details, I would like to mention that, we are not saving this excel anywhere and users are prompted to save this excel if they wish to. Also we have multiple reports and the report columns are dynamic, populated in runtime.
AnSWER:-
This is the code that I am using to export to excel:
{
tblLockedReport.Border = 2;
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=test.xls");
Response.Charset = string.Empty;
Response.ContentType = "application/vnd.ms-excel.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
//Create a form to contain the panel
HtmlForm htmlFrm = new HtmlForm();
PanelReport.Parent.Controls.Add(htmlFrm);
htmlFrm.Attributes["runat"] = "server";
htmlFrm.Controls.Add(PanelReport);
htmlFrm.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
tblLockedReport.Border = 0;
}
0 comments:
கருத்துரையிடுக