private void Save_Click(object sender, System.EventArgs e)
{
try
{
string strFileName = "TransTooLong"+System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() ;
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename="+ strFileName +".xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//
Response.ContentType = "application/ms-excel";//
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.IO.TextWriter oStringWriter1=new System.IO.TextWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter (oStringWriter1);
this.dataGrid.RenderControl( oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
catch(System.Exception a)
{
Response.Write("<Script>window.alert('"+a.Message +"'</Script>");
}
//----------写文件
// try
// {
// StreamWriter sw =File.CreateText("C:/TestFile.txt");
//
// // Add some text to the file.
//
// sw.Write("This is the ");
// sw.WriteLine("header for the file.");
// sw.WriteLine("-------------------");
// // Arbitrary objects can also be written to the file.
// sw.Write("The date is: ");
// sw.WriteLine(DateTime.Now);
// sw.Close();
// }
// catch(System.Exception b)
// {
// Response.Write("<Script>window.alert('"+b.Message +"'</Script>");
// }
}
{
try
{
string strFileName = "TransTooLong"+System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() ;
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename="+ strFileName +".xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//
Response.ContentType = "application/ms-excel";//
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.IO.TextWriter oStringWriter1=new System.IO.TextWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter (oStringWriter1);
this.dataGrid.RenderControl( oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
catch(System.Exception a)
{
Response.Write("<Script>window.alert('"+a.Message +"'</Script>");
}
//----------写文件
// try
// {
// StreamWriter sw =File.CreateText("C:/TestFile.txt");
//
// // Add some text to the file.
//
// sw.Write("This is the ");
// sw.WriteLine("header for the file.");
// sw.WriteLine("-------------------");
// // Arbitrary objects can also be written to the file.
// sw.Write("The date is: ");
// sw.WriteLine(DateTime.Now);
// sw.Close();
// }
// catch(System.Exception b)
// {
// Response.Write("<Script>window.alert('"+b.Message +"'</Script>");
// }
}