以下只是简单的实现了下,并没有按三层架构的要求做
protected void btnDetail_Click(object sender, EventArgs e)
{
tb_view.Visible = false;
if (ReadMeetingDate.Value == "")
{
Response.Write("<script>window.alert('未选择时间')</script>");
return;
}
string sql = "SP_TravalOFFList N'" + ReadMeetingDate.Value + "',N'" + ddl_site.SelectedValue + "'";
DataSet ds = SQLHelper.ExecuteDataSet(SQLHelper.Conn, CommandType.Text, sql, null);
if (ds.Tables[0].Rows.Count == 0)
{
downloadMes.Visible = true;
return;
}
DataTable dtExport = ds.Tables[0];
Aspose.Cells.License lic = new Aspose.Cells.License();
lic.SetLicense("Aspose.Cells.lic");
Aspose.Cells.Workbook xlsBK = new Aspose.Cells.Workbook();
Aspose.Cells.Worksheet xlsST = null;
xlsST = xlsBK.Worksheets[0];
xlsST.Cells[0, 1].PutValue("部门名称");
xlsST.Cells[0, 2].PutValue("卡号");
xlsST.Cells[0, 3].PutValue("姓名");
xlsST.Cells[0, 4].PutValue("类别");
xlsST.Cells[0, 5].PutValue("班别");
xlsST.Cells[0, 6].PutValue("开始时间");
xlsST.Cells[0, 7].PutValue("结束时间");
xlsST.Cells[0, 8].PutValue("天数");
xlsST.Cells[0, 9].PutValue("事由");
for (int i = 0; i < dtExport.Rows.Count;i++ )
{
xlsST.Cells[i + 1, 0].PutValue(i+1);
xlsST.Cells[i + 1, 1].PutValue(dtExport.Rows[i]["Depart_C"].ToString());
xlsST.Cells[i + 1, 2].PutValue(dtExport.Rows[i]["EmpyNo1"].ToString());
xlsST.Cells[i + 1, 3].PutValue(dtExport.Rows[i]["NAME_C"].ToString());
xlsST.Cells[i + 1, 4].PutValue(dtExport.Rows[i]["KIND_TYPE"].ToString());
xlsST.Cells[i + 1, 5].PutValue(dtExport.Rows[i]["WorkRule"].ToString());
xlsST.Cells[i + 1, 6].PutValue(dtExport.Rows[i]["ApplyBeginTime"].ToString());
xlsST.Cells[i + 1, 7].PutValue(dtExport.Rows[i]["ApplyEndTime"].ToString());
xlsST.Cells[i + 1, 8].PutValue(dtExport.Rows[i]["DiffDay"].ToString());
xlsST.Cells[i + 1, 9].PutValue(dtExport.Rows[i]["Bak"].ToString());
}
System.IO.MemoryStream ms = xlsBK.SaveToStream();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ContentType = "application/x-msexcel";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=Export" + DateTime.Now.ToString() + ".xls");
HttpContext.Current.Response.BinaryWrite(ms.ToArray());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
ms.Close();
}