使用母版页时如何将动态生成的HTML表导出到VB.NET中的Excel [英] How to Export dynamically generated HTML table to Excel in VB.NET when using Master Page
问题描述
您好专家,
我正在创建一个Web应用程序,其中包含许多要生成的报告.我正在动态创建一个表",并根据数据库中的记录添加"tr"和"td",并将其附加到String Builder,最后将字符串分配给Div Tag的InnerHTML.
我想为用户提供将表导出到Excel",并且当它是单个页面时,可以使用以下代码导出包括CSS样式的内容.但是当我进入内容页面(具有母版页面)时,以下代码不起作用.
Hello Experts,
I am creating an Web application contains lot of reports to be generated. I am dynamically creating a "table" and adding "tr" and "td" based on the records from Database and appending it to String Builder and Finally assigning the string to InnerHTML of Div Tag.
I want to provide Exporting the Table to Excel for user and I am able to export the contents including CSS Style using the below code when it is an individual page. But the below code is not working when I go for Content Page(Having Master Page).
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.Charset = ""
GenerateEvalReport() '' Generating the Table here and assigning to DIV.InnerHTML
Response.AddHeader("content-disposition", "EvalReport.xls")
Response.ContentType = "application/vnd.ms-excel"
'' Response.ContentType = "application/ms-excel" -- Tried this also. Not Working
Dim objRow As New HtmlTableRow
Dim objCell As New HtmlTableCell
objCell.Controls.Add(tblBody) '' ''tblBody''- Id of my Dynamic Table
objRow.Cells.Add(objCell)
table1.Rows.Add(objRow) '' Have one more Table as ''table1''
table1.RenderControl(oHTMLTextWrite)
Response.Write(oStringWriter.ToString())
Response.Flush()
Response.End()
使用Response.Write(oStringWriter.ToString())
时,出现两个不同的错误(因为我在2页中使用了相同的代码)
1. Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息
2.无法评估表达式.线程已终止.
你能指出我犯错的地方吗?
非常感谢.
I am getting two different Errors(since I have used the same code in 2 pages) when using Response.Write(oStringWriter.ToString())
1. Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed
2. Unable to evaluate Expression. Thread Aborted.
Can you please point me where I made mistake.
Thanks a lot.
推荐答案
检查这些链接
http://www.velocityreviews.com/forums/t584896-export- html-table-to-excel-file.html [ ^ ]
http://www.daniweb.com/web-development/aspnet/threads/54143 [ ^ ]
Check These links
http://www.velocityreviews.com/forums/t584896-export-html-table-to-excel-file.html[^]
http://www.daniweb.com/web-development/aspnet/threads/54143[^]
引用此链接:
http://www.dotnetspider.com/resources/5587-Export-Table-data- Excel.aspx [ ^ ]
Refer this link:
http://www.dotnetspider.com/resources/5587-Export-Table-data-Excel.aspx[^]
我在母版页中使用了三个内容占位符,还禁用了内容页中的Viewstate.
我所做的是在内容页面中启用了Viewstate,并在内容页面中添加了三个asp:contents. 1代表Head,1代表AJAX相关的脚本,1代表非AJAX相关的脚本.然后上面相同的代码对我来说很好用.
I have Used Three Content Place Holders in Master Page and also Disabled the Viewstate in Content Page.
What I did is enable the Viewstate in Content Page and added Three asp:contents in Content Page. 1 for Head, 1 for AJAX related scripts and 1 for non AJAX related Scripts. Then the same above code works fine for me.
这篇关于使用母版页时如何将动态生成的HTML表导出到VB.NET中的Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!