关于导出到excel
这是getdata_md.aspx.cs
protected void alldata_Click1(object sender, EventArgs e)//查询
{
string type = rep_type.Value;//类型
var con = condition.Value;//条件
var st_date = st_time.Value;//开始时间
var ed_date = ed_time.Value;//结束时间
StringBuilder html = new StringBuilder();
DataTable dt = new DataTable();
if (type == "1")
{
if (con == "1")
{
string sql_1 = "";
if (hos_no.Value != "37" && (fillid.Value != "151" || fillid.Value != "153"))//
{
sql_1 = @"select a.flag,a.hos_name, a.sort_id as a_sort_id,b.sort_id as b_sort_id,a.m_name,a.card_id,a.get_hiv_time,a.l_menstruation,
b.pregnancy,b.brithday,b.perinatal,b.u_medication,
b.pregnancy_time+'('+ltrim(b.pregnancy_week)+')' as pregnancy_time,
b.s_situation,b.HIV_medication,isnull(b.children_id,'/') as children_id
from tab_3_I a,tab_3_II b
where a.hos_no*=b.hos_no
and a.card_id*=b.card_id
and a.filldate between '" + st_date + "' and '" + ed_date + "' and a.hos_no='" + hos_no.Value + "' and a.fillid='" + fillid.Value + "' order by a.hos_no asc";
}
else
{
sql_1 = @"select a.flag,a.hos_name, a.sort_id as a_sort_id,b.sort_id as b_sort_id,a.m_name,a.card_id,a.get_hiv_time,a.l_menstruation,
b.pregnancy,b.brithday,b.perinatal,b.u_medication,
b.pregnancy_time+'('+ltrim(b.pregnancy_week)+')' as pregnancy_time,
b.s_situation,b.HIV_medication,isnull(b.children_id,'/') as children_id
from tab_3_I a,tab_3_II b
where a.hos_no*=b.hos_no
and a.card_id*=b.card_id
and a.filldate between '" + st_date + "' and '" + ed_date + "' order by a.hos_no asc";
}
dt = sqlHelper.getSqlHelper().Excute(sql_1);
countdata.InnerText = Convert.ToString(dt.Rows.Count);
}
if (con == "2")//末次月经时间
{
string sql_1 = "";
if (hos_no.Value != "37" && (fillid.Value != "151" || fillid.Value != "153"))//不是保健院的统计员
{
sql_1 = @"select a.flag,a.hos_name,a.sort_id as a_sort_id,b.sort_id as b_sort_id,a.m_name,a.card_id,a.get_hiv_time,a.l_menstruation,
b.pregnancy,b.brithday,b.perinatal,b.u_medication,
b.pregnancy_time+'('+ltrim(b.pregnancy_week)+')' as pregnancy_time,
b.s_situation,b.HIV_medication,isnull(b.children_id,'/') as children_id
from tab_3_I a,tab_3_II b
where a.hos_no*=b.hos_no
and a.card_id*=b.card_id
and a.l_menstruation between '" + st_date + "' and '" + ed_date + "' and a.hos_no='" + hos_no.Value + "' and a.fillid='" + fillid.Value + "' order by a.hos_no asc";
}
else
{
sql_1 = @"select a.flag,a.hos_name, a.sort_id as a_sort_id,b.sort_id as b_sort_id,a.m_name,a.card_id,a.get_hiv_time,a.l_menstruation,
b.pregnancy,b.brithday,b.perinatal,b.u_medication,
b.pregnancy_time+'('+ltrim(b.pregnancy_week)+')' as pregnancy_time,
b.s_situation,b.HIV_medication,isnull(b.children_id,'/') as children_id
from tab_3_I a,tab_3_II b
where a.hos_no*=b.hos_no
and a.card_id*=b.card_id
and a.l_menstruation between '" + st_date + "' and '" + ed_date + "' order by a.hos_no asc";
}
dt = sqlHelper.getSqlHelper().Excute(sql_1);
countdata.InnerText = Convert.ToString(dt.Rows.Count);
}
html.Append("<table id='data' style='width:140%;border-collapse:collapse; border:1px solid gray;font-size:11px;' border='1'>");
html.Append("<tr style='background-color:#FFCC33'><th>医院名称</th><th>产妇姓名</th><th>孕妇编号</th><th>儿童编号</th><th>确认感染时间</th><th>未次月经</th><th>妊娠结局</th>");
html.Append("<th>分娩时间</th><th>围产儿转归</th><th>药物应用情况</th><th>开始用药时间</th>");
html.Append("<th>新生儿存活情况</th><th>新生婴儿药物应用情况</th><th>状态</th><th>表3-I</th><th>表3-II</th><th>表3-III</th></tr>");
html.Append("<tbody>");
for (int i = 0; i < dt.Rows.Count; i++)
{
if (i % 2 == 0)
{
html.Append("<tr style='text-align:center;cursor:pointer; background-color:#ccff99;font-size:11px;'>");
}
else
{
html.Append("<tr style='text-align:center;cursor:pointer;font-size:11px;'>");
}
html.Append("<td>" + dt.Rows[i]["hos_name"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["m_name"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["card_id"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["children_id"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["get_hiv_time"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["l_menstruation"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["pregnancy"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["brithday"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["perinatal"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["u_medication"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["pregnancy_time"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["s_situation"].ToString().Trim() + "</td>");
html.Append("<td>" + dt.Rows[i]["HIV_medication"].ToString().Trim() + "</td>");
}
这是getdata_md.aspx文件
</head>
<body>
<form id="form1" runat="server">
<div id="header">
报表类型:<select runat="server" id="rep_type" style="width: 80px;">
<option value="2">梅毒</option>
</select>
条件:<select runat="server" id="condition" style="width: 100px;">
<option value="1">上报时间</option>
<option value="2">末次月经时间</option>
</select>
时间:从<input runat="server" type="text" id="st_time" onfocus="WdatePicker();" onclick="WdatePicker();"
style="width: 75px;" />至<input type="text" runat="server" id="ed_time" onfocus="WdatePicker();"
onclick="WdatePicker();" style="width: 75px;" />
<asp:Button ID="alldata" runat="server" Text="统计" Style="width: 80px;" OnClick="alldata_Click1" />
<div>
总数量:<label id="countdata" runat="server"></label>
过滤:<input type="text" id="content_txt" style="width: 90px;" /></div>
</div>
<div id="show_detail" runat="server" style="margin-top: 5px; border-top: 2px solid gray;">
</div>
<input type="hidden" runat="server" id="fillid" />
<input type="hidden" runat="server" id="hos_no" />
</form>
</body>
</html>
如何在getdata_md.aspx文件中添加一个导出到excel按钮的功能? 或者能否将getdata_md.aspx.cs文件中table id的值取到getdata_md_aspx