I'm creating two HTML tables in vb.net in a string variable and appending the string text to the innerhtml of an aspx page at runtime. The code to this is as below (This is a sample code):
我在vb.net中用字符串变量创建两个HTML表,并在运行时将字符串文本附加到aspx页的innerhtml。这个代码如下(这是一个示例代码):
Dim oBuilder as stringbuilder
With oBuilder
.Append("<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">")
.Append("<head>")
.Append("<meta http-equiv=""Content-Type"" content=""text/html;charset=windows-1252"">")
.Append("<!--[if gte mso 9]>")
.Append("<xml>")
.Append("<x:ExcelWorkbook>")
.Append("<x:ExcelWorksheets>")
.Append("<x:ExcelWorksheet>")
.Append("<x:Name>Summary</x:Name>")
.Append("<div>")
.Append("<table style="" border:solid 1px black; "">")
.Append("<tr>")
.Append("<td>Column 1</td>")
.Append("</tr>")
.Append("</table>")
.Append("</div>")
.Append("<div>")
.Append("<table style="" border:solid 1px black; "">")
.Append("<tr>")
.Append("<td>Column 1 - Table 2</td>")
.Append("</tr>")
.Append("</table>")
.Append("</div>")
End With
LogDetails.InnerHtml = oBuilder.ToString
The aspx page actually displays the tables fine (one below the other). I tried adding the following lines and use office functionality with XML to name the worksheets. I was able to create and name two worksheets:
aspx页面实际上显示了表格(一个在另一个之下)。我尝试添加以下行,并使用XML的办公功能来命名工作表。我能够创建并命名两个工作表:
.Append("<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">")
.Append("<head>")
.Append("<meta http-equiv=""Content-Type"" content=""text/html;charset=windows-1252"">")
.Append("<!--[if gte mso 9]>")
.Append("<xml>")
.Append("<x:ExcelWorkbook>")
.Append("<x:ExcelWorksheets>")
.Append("<x:ExcelWorksheet>")
.Append("<x:Name>Summary</x:Name>")
.Append("</x:ExcelWorksheet>")
.Append("<x:ExcelWorksheet>")
.Append("<x:Name>Summary no 2</x:Name>")
.Append("</x:ExcelWorksheet>")
.Append("</xml>")
.Append("<![endif]-->")
.Append("</head>")
.Append("<body>")
.Append(oBuilder)
.Append("</body>")
.Append("</html>")
Post renderring the page, I click a button to export the tables to excel. My button click event does the following:
在渲染页面后,我单击一个按钮将表导出为excel。我的按钮单击事件执行以下操作:
Context.Response.ContentType = "application/ms-excel"
Context.Response.AddHeader("content-disposition", "attachment; filename=" + Session("ExcelFile").Trim + "")
Context.Response.AddHeader("Content-Transfer-Encoding", "binary")
Context.Response.Write(LogDetails.InnerHtml)
This button gives me a save / open dialog box. When I open the saved excel sheet, I find that it has the two tables one below the other ... I would like the tables to be on seperate worksheets. I don’t want to recreate my entire code because it has years of work … Is there a way that I can put the first HTML table in the "summary" worksheet and the second HTML table into the "summary no 2" worksheet without having to rework the entire code?
这个按钮给我一个保存/打开对话框。当我打开保存的excel表时,我发现它有一个在另一个下面的两个表...我希望这些表位于单独的工作表上。我不想重新创建我的整个代码,因为它有多年的工作...有没有办法可以将第一个HTML表放在“摘要”工作表中,将第二个HTML表放入“摘要号2”工作表中,而不必重做整个代码?
Any help will be greatly appreciated as I have been researching on this for over 3 days now ... (Doesn't say much about my research skills)
任何帮助将不胜感激,因为我已经研究了这个超过3天... ...(我的研究技巧并没有多说)
Regards, Sunny
1 个解决方案
#1
0
I supose you need to render the first table into the first spreadsheet, then change the active worksheet and render the second table.
我想你需要将第一个表格渲染到第一个电子表格中,然后更改活动工作表并渲染第二个表格。
#1
0
I supose you need to render the first table into the first spreadsheet, then change the active worksheet and render the second table.
我想你需要将第一个表格渲染到第一个电子表格中,然后更改活动工作表并渲染第二个表格。