1

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):

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:

        .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:

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?

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)

Regards, Sunny

4

1 回答 1

0

我假设您需要将第一个表格呈现到第一个电子表格中,然后更改活动工作表并呈现第二个表格。

于 2012-09-24T10:33:41.730 回答