How to export more than one repeater to a single excel sheet - VB

Martha 116 Reputation points
2021-06-09T14:29:03.22+00:00

Hi all,

I am looking to display information from two repeaters in a sing excel sheet. I want the layout to ideally be:

title1 | title2 | title3 |
some of repeater 1 info | all of repeater 2 info | rest of repeater 1 info |

I am not sure this is possible so even to display all of repeater 1 info beside all of repeater 2 info will do if the above layout is not possible.

The below code (ASP.NET - VB) I have only exports 1 reapeter at a time. If anyone could help me display the second that would be great

Thanks in advance!

 Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Response.Clear()
        Response.Buffer = True
        Response.AddHeader("content- 
        disposition","attachment;filename=RepeaterExport.xls")
        Response.Charset = ""
        Response.ContentType = "application/vnd.ms-excel"

        Dim sw As New StringWriter()
        Dim hw As New HtmlTextWriter(sw)

        Rpt1.RenderControl(hw)
        Response.Output.Write(sw.ToString())
        Response.Flush()
        Response.End()

 End Sub
        
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,457 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,714 questions
{count} votes

Accepted answer
  1. Martha 116 Reputation points
    2021-06-10T11:38:40.807+00:00

    I have used your concept to get the code to sort of work. I seem to be having an issue displaying the footer of my code. the footer calculates a total of the columns.
    The code works when I comment the footer out. If anyone knows why this might be or could help that would be great.
    Thanks

        Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
                Response.Clear()
                Response.Buffer = True
                Response.AddHeader("content-disposition", "attachment;filename=RepeaterExport.xls")
                Response.Charset = ""
                Response.ContentType = "application/vnd.ms-excel"
    
                Dim sw As New StringWriter()
                Dim hw As New HtmlTextWriter(sw)
    
                Dim tb As New Table()
                Dim tr1 As New TableRow()
                Dim cell1 As New TableCell()
    
                cell1.Controls.Add(Rpt1)
                tr1.Cells.Add(cell1)
                Dim cell3 As New TableCell()
                cell3.Controls.Add(Rpt2)
                Dim cell2 As New TableCell()
                cell2.Text = " "
    
                tr1.Cells.Add(cell2)
                tr1.Cells.Add(cell3)
                tb.Rows.Add(tr1)
    
                tb.RenderControl(hw)
    
                Response.Output.Write(sw.ToString())
                Response.Flush()
                Response.End()
    
            End Sub
    
    
                <FooterTemplate>
                    <tr>
    
                        <td></td>
                        <td></td>
                        <td>
                            <asp:TextBox CssClass="ttl" ReadOnly="true" ID="Label1" runat="server"></asp:TextBox></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
    
                        <td>
                            <asp:TextBox CssClass="ttl" ReadOnly="true" ID="Label2" runat="server"></asp:TextBox></td>
                        <td>
                            <asp:TextBox CssClass="ttl2" ReadOnly="false" ID="Label3" runat="server"></asp:TextBox></td>
                        <td>
                            <asp:TextBox CssClass="ttl2" ReadOnly="true" ID="Label4" runat="server"></asp:TextBox></td>
                    </tr>
                    </table>
    
                </FooterTemplate>
    
    
            </asp:Repeater>
    

1 additional answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,076 Reputation points
    2021-06-10T05:49:00.91+00:00

    Hi @Martha ,
    According to your description,I suggest you could change the <table> when you export.Just like this:

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)  
        Response.Clear()  
        Response.Buffer = True  
        Response.AddHeader("content-disposition", "attachment;filename=RepeaterExport.xls")  
        Response.Charset = ""  
        Response.ContentType = "application/vnd.ms-excel"  
        Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter()  
        Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)  
        Dim stringWrite2 As System.IO.StringWriter = New System.IO.StringWriter()  
        Dim htmlWrite2 As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite2)  
        Rep.RenderControl(htmlWrite)  
        Rep2.RenderControl(htmlWrite2)  
        Response.Write("<table>")  
        Response.Write("<tr>")  
        Response.Write("<td>")  
        Response.Write(stringWrite.ToString())  
        Response.Write("</td>")  
        Response.Write("<td>")  
        Response.Write(stringWrite2.ToString())  
        Response.Write("</td>")  
        Response.Write("</tr>")  
        Response.Write("</table>")  
        Response.[End]()  
    End Sub  
    

    104029-new-text-document.txt
    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.