在Excel中导出HTML表但在Excel打开时它会使Excel停止工作 [英] HTML Table Export in Excel But When Excel Open it gives Excel Stop Working

查看:117
本文介绍了在Excel中导出HTML表但在Excel打开时它会使Excel停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个带有两个单选按钮的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.

推荐答案





我发现解决方案是。我正在使用float:在DailySales报告中留下,所以当我导出到excel并尝试打开它的给出错误。现在我删除float:从dailysales表中删除它正在工作。



谢谢
Hi,

I have found the solutions is. I am using float:left in DailySales report so when i am exported into excel and try to open its give error. Now I am remove float:left from dailysales table it's working.

Thanks


建议:当您提出问题时,您也不必使用解决方案。

- 您可以改善问题或发表评论以与帮助者讨论。

- 当找到解决方案时,你可以说哪个解决方案是有用的。

- 当找到解决方案时,关闭问题也是一个好习惯,因为一个封闭的问题说每个帮助者不需要更多的帮助。
Advice: When you ask a question, you don't have to use also a solution.
- You may Improve question or post comments to discuss with helpers.
- When the solution is found, you can say which solution was helpful.
- When the solution is found, it is also a good practice to close the question as a closed question says every helper that no more help is needed.


这篇关于在Excel中导出HTML表但在Excel打开时它会使Excel停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆