111,093
社区成员




protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//你要绑定的数据类型的列
e.Row.Cells[1].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
// 你要绑定的日期类型的列
e.Row.Cells[2].Attributes.Add("style", "vnd.ms-excel.numberformat:yyyy/mm/dd hh:mm:ss");
// 以此类推...
}
}
strComm = "insert into [Sheet1$] (数量,单价,总价) values ('" + TabXu.Rows[i][16].ToString() + "','" + TabXu.Rows[i][17].ToString() + "','" + TabXu.Rows[i][18].ToString() + "')";
string strConn = "provider=Microsoft.Jet.OLEDB.4.0;data source=" + _fileName + ";Extended Properties=Excel 8.0;";
OleDbConnection oleConn = new OleDbConnection(strConn);
OleDbDataAdapter oleAdap = new OleDbDataAdapter(strComm, oleConn);
DataSet ds = new DataSet();
oleConn.Open();
oleAdap.Fill(ds, "ExcelData");
oleConn.Close();
private void ExportToExcel(string filename)
{
string str = DateTime.Today.Year.ToString() + DateTime.Today.Month.ToString();
string s_filename = str +filename+ ".xls";
Response.Clear();
Response.Buffer = true;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + s_filename);
Response.ContentEncoding = System.Text.Encoding.Default;//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为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.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.GridView1.RenderControl(oHtmlTextWriter);
//Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-7");
//Response.Charset = "GB2312";
Response.Write(oStringWriter.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}