///
/// 导出数据
///
///
///
protected void btnprint_Click(object sender, EventArgs e)
{
string sql = “”;
if (txtKey.Text == “”)
sql = “select * from VI_GongZi where (” + ddltype.SelectedValue + " like ‘%" + txtKey.Text.Trim() + "%’) order by GongZiId desc";
else
sql = “select * from VI_GongZi order by GongZiId desc”;
DataTable dt = DB.getDataTable(sql);
StringBuilder str = new StringBuilder();
str.Append("<meta http-equiv=\"content-type\" content=\"application/excel;charset=utf-8\" />");
str.Append("<table border='1'>");
str.Append("<tr style='background:#cccccc;'>");
str.Append("<td>员工编号 </td>");
str.Append("<td>员工姓名 </td>");
str.Append("<td>考勤说明 </td>");
str.Append("<td>添加时间 </td>");
str.Append("<td>基本工资 </td>");
str.Append("<td>加班费 </td>");
str.Append("<td>出差补助 </td>");
str.Append("<td>异常考勤扣款 </td>");
str.Append("<td>合计工资 </td>");
str.Append("</tr>");
foreach (DataRow row in dt.Rows)
{
str.Append("<tr>");
str.Append("<td>" + row["userid"] + "</td><td>" + row["username"] + "</td><td>" + row["title"] + "</td>");
str.Append("<td>" + row["addtime"] + "</td><td>" + row["gongzi"] + "</td><td>" + row["jiaban"] + "</td>");
str.Append("<td>" + row["chuchai"] + "</td><td>" + row["koukuan"] + "</td><td>" + row["total"] + "</td>");
str.Append("</tr>");
}
str.Append("</table>");
this.Page.Response.Clear();
this.Page.Response.Buffer = false;
this.Page.Response.Charset = "UTF-8";
this.Page.Response.AppendHeader("Content-Disposition", "attachment;filename=Print_GongZi_Data.xls");
this.Page.Response.ContentEncoding = Encoding.UTF8;
this.Page.Response.ContentType = "application/excel";
this.Page.EnableViewState = false;
this.Page.Response.Write(str.ToString());
this.Page.Response.End();
}