合并最新
This commit is contained in:
@@ -4,7 +4,9 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
|
||||
using FineUIPro.Web.Controls;
|
||||
using System.Text;
|
||||
using AspNet = System.Web.UI.WebControls;
|
||||
namespace FineUIPro.Web.HSSE.InformationProject
|
||||
{
|
||||
public partial class AccidentCauseReport : PageBase
|
||||
@@ -273,5 +275,113 @@ namespace FineUIPro.Web.HSSE.InformationProject
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 导出按钮
|
||||
/// 导出按钮
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnOut_Click(object sender, EventArgs e)
|
||||
{
|
||||
Response.ClearContent();
|
||||
string filename = Funs.GetNewFileName();
|
||||
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("职工伤亡事故原因分析报" + filename, System.Text.Encoding.UTF8) + ".xls");
|
||||
Response.ContentType = "application/excel";
|
||||
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
||||
this.Grid1.PageSize = 500;
|
||||
this.BindGrid();
|
||||
Response.Write(GetGridTableHtml(Grid1));
|
||||
Response.End();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出方法
|
||||
/// </summary>
|
||||
/// <param name="grid"></param>
|
||||
/// <returns></returns>
|
||||
private string GetGridTableHtml(Grid grid)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
MultiHeaderTable mht = new MultiHeaderTable();
|
||||
mht.ResolveMultiHeaderTable(Grid1.Columns);
|
||||
|
||||
|
||||
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
|
||||
|
||||
|
||||
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
|
||||
|
||||
foreach (List<object[]> rows in mht.MultiTable)
|
||||
{
|
||||
sb.Append("<tr>");
|
||||
foreach (object[] cell in rows)
|
||||
{
|
||||
|
||||
int rowspan = Convert.ToInt32(cell[0]);
|
||||
int colspan = Convert.ToInt32(cell[1]);
|
||||
GridColumn column = cell[2] as GridColumn;
|
||||
if (!column.Hidden)
|
||||
{
|
||||
sb.AppendFormat("<th{0}{1}{2}>{3}</th>",
|
||||
rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "",
|
||||
colspan != 1 ? " colspan=\"" + colspan + "\"" : "",
|
||||
colspan != 1 ? " style=\"text-align:center;\"" : "",
|
||||
column.HeaderText);
|
||||
}
|
||||
|
||||
}
|
||||
sb.Append("</tr>");
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
foreach (GridRow row in grid.Rows)
|
||||
{
|
||||
sb.Append("<tr>");
|
||||
int i = 0;
|
||||
foreach (GridColumn column in mht.Columns)
|
||||
{
|
||||
|
||||
string html = row.Values[column.ColumnIndex].ToString();
|
||||
|
||||
if (column.ColumnID == "tfNumber")
|
||||
{
|
||||
html = (row.FindControl("spanNumber") as System.Web.UI.HtmlControls.HtmlGenericControl).InnerText;
|
||||
}
|
||||
else if (column.ColumnID == "tfGender")
|
||||
{
|
||||
html = (row.FindControl("labGender") as AspNet.Label).Text;
|
||||
}
|
||||
|
||||
if (i <= 6 && j % 2 == 0)
|
||||
{
|
||||
if (!column.Hidden)
|
||||
{
|
||||
|
||||
sb.AppendFormat("<td rowspan='2'>{0}</td>", html);
|
||||
}
|
||||
}
|
||||
else if (i > 6)
|
||||
{
|
||||
if (!column.Hidden)
|
||||
{
|
||||
sb.AppendFormat("<td >{0}</td>", html);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
j++;
|
||||
sb.Append("</tr>");
|
||||
|
||||
}
|
||||
|
||||
sb.Append("</table>");
|
||||
|
||||
return sb.ToString();
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user