B
ben
Hi,
I have an aspx page with an export to excel functionality....it opens
a dialog box asking the client to save/open the xls file.However this
works fine on my machine but does not work on another PC and
onclicking the export button( where all the code is written)....it
does nothing.....i am pasting the code below...any info will be useful
Also, one of the columns in the datagrid is 16 charasters long(it is
numberic data but stored as varchar in DB); it gets converted to
numeric form in the spreadsheet..how do i make it as text....
Thanks in advance for any inputs
private void Page_Load(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer=true;
Response.ContentType="application/vnd.ms-excel";
//Response.AddHeader("content-disposition","attachment;filename=myfile.xls";
Response.AddHeader("content-disposition","attachment;filename=myfile"+"_"+DateTime.Now.Day.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Year.ToString()+"_"+DateTime.Now.Hour.ToString()+"_"+DateTime.Now.Minute.ToString()+"_"+DateTime.Now.Second.ToString()+".xls");
Response.Charset="";
this.EnableViewState=false;
System.IO.StringWriter SW= new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw= new HtmlTextWriter(SW);
string connstr="";
string selecttext="";
SqlConnection myconnection=new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand(selecttext,myconnection);
myconnection.Open();
SqlDataAdapter da= new SqlDataAdapter();
da.SelectCommand=cmd;
DataTable myds= new DataTable();
da.Fill(myds);
DataGrid dg= new DataGrid();
dg.DataSource= myds;
dg.DataBind();
//this.ClearControls(dg);
dg.RenderControl(hw);
Response.Write(SW.ToString());
Response.End();
// Put user code to initialize the page here
}
This is the code in the aspx page which will open on clicking the
export to excel button on the main aspx page.....however nothign will
get displayed in this and the dialog box to save/open will directly
pop up....
P.S Checked the folder options to be accurate(for XLS format)
Thanks again
Ben Arthur
I have an aspx page with an export to excel functionality....it opens
a dialog box asking the client to save/open the xls file.However this
works fine on my machine but does not work on another PC and
onclicking the export button( where all the code is written)....it
does nothing.....i am pasting the code below...any info will be useful
Also, one of the columns in the datagrid is 16 charasters long(it is
numberic data but stored as varchar in DB); it gets converted to
numeric form in the spreadsheet..how do i make it as text....
Thanks in advance for any inputs
private void Page_Load(object sender, System.EventArgs e)
{
Response.Clear();
Response.Buffer=true;
Response.ContentType="application/vnd.ms-excel";
//Response.AddHeader("content-disposition","attachment;filename=myfile.xls";
Response.AddHeader("content-disposition","attachment;filename=myfile"+"_"+DateTime.Now.Day.ToString()+DateTime.Now.Month.ToString()+DateTime.Now.Year.ToString()+"_"+DateTime.Now.Hour.ToString()+"_"+DateTime.Now.Minute.ToString()+"_"+DateTime.Now.Second.ToString()+".xls");
Response.Charset="";
this.EnableViewState=false;
System.IO.StringWriter SW= new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw= new HtmlTextWriter(SW);
string connstr="";
string selecttext="";
SqlConnection myconnection=new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand(selecttext,myconnection);
myconnection.Open();
SqlDataAdapter da= new SqlDataAdapter();
da.SelectCommand=cmd;
DataTable myds= new DataTable();
da.Fill(myds);
DataGrid dg= new DataGrid();
dg.DataSource= myds;
dg.DataBind();
//this.ClearControls(dg);
dg.RenderControl(hw);
Response.Write(SW.ToString());
Response.End();
// Put user code to initialize the page here
}
This is the code in the aspx page which will open on clicking the
export to excel button on the main aspx page.....however nothign will
get displayed in this and the dialog box to save/open will directly
pop up....
P.S Checked the folder options to be accurate(for XLS format)
Thanks again
Ben Arthur