问题描述
大家好,
我有一个带有两个单选按钮的aspx页面和两个带有runat服务器和一个导出按钮的div框。
1.单选按钮名称:DSR报告
2.单选按钮名称:每日销售
开单选按钮选择我从数据库获取数据,并在c#中使用stringBuilder创建html表并绑定到div box innerhtml属性。
我的html表显示正常但是出现问题时当我打开这个excel时,我将我的每日销售html表导出到excel中,显示excel停止工作但导出excel的DSR报告没问题。
我我使用相同的Excel导出代码但我不明白在Excel中导出第二个html表有什么问题。
导出代码如下导出按钮单击
Hi Everyone,
I have a aspx page with two radio button and two div box with runat server and one export button.
1. Radio button Name: DSR Report
2. Radio Button Name: Daily Sales
On radio button selection i have got data from database and creating html table in c# with stringBuilder and bind to div box innerhtml property.
My html table is display properly but problem when I export my "Daily Sales" html table into excel when i open this excel it display excel stop working but no problem with exported excel of "DSR Report".
I am using same Exported Code for Excel But i donot understand what is the problem with exporting second html table in excel.
Export Code is below on export button click
string fileName = string.Empty;
if (rdDailySales.Checked)
fileName = rdDailySales.Text + "_" + DateTime.Now.Date.Day.ToString() + "_" + DateTime.Now.Date.Month.ToString() + "_" + DateTime.Now.Date.Year.ToString();
else
fileName = rdDsr.Text + "_" + DateTime.Now.Date.Day.ToString() + "_" + DateTime.Now.Date.Month.ToString() + "_" + DateTime.Now.Date.Year.ToString();
Response.Clear();
Response.Charset = "";
Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/ms-excel.xls";
Response.AddHeader("content-disposition", "attachment;filename=" + fileName + ".xls");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
firstRow.RenderControl(hw);
//sencondRow.RenderControl(hw);
if (rdDsr.Checked)
dbReport.RenderControl(hw);
//divbreak.RenderControl(hw);
//thirdRow.RenderControl(hw);
if (rdDailySales.Checked)
dbReport1.RenderControl(hw);
FileInfo fi = new FileInfo(Server.MapPath("../Styles/jquery.dataTablesExcel.css"));
StringBuilder sb1 = new StringBuilder();
StreamReader sr = fi.OpenText();
while (sr.Peek() >= 0)
{
sb1.Append(sr.ReadLine());
}
sr.Close();
Response.Write("<html><head><style type='text/css'>" + sb1.ToString() + "</style><head>" + sw.ToString() + "</html>");
sw = null;
hw = null;
Response.Flush();
Response.End();
请指导我导出第二个html表时缺少什么。
Please guide me what is missing in exporting second html table.
推荐答案
这篇关于在Excel中导出HTML表但在Excel打开时它会使Excel停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!