Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3398008
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:35:51+00:00 2026-05-18T04:35:51+00:00

I’m exporting some data I have in a database into Excel. Although the below

  • 0

I’m exporting some data I have in a database into Excel. Although the below code works fine, I would like to know how to manipulate headers, colours, and generally the way the cells look?

page.aspx

   <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"  SelectCommand="SELECT ID, Number, Title, Name FROM Requests">
 <SelectParameters>
        <asp:QueryStringParameter DefaultValue="" Name="ID" 
            QueryStringField="ID" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

  <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" 
    AutoGenerateRows="False" DataKeyNames="RequestID" DataSourceID="SqlDataSource1">
    <Fields>
           <asp:BoundField DataField="ID" HeaderText="ID" 
            SortExpression="ID" InsertVisible="False" ReadOnly="True" />
        <asp:BoundField DataField="Number" HeaderText="Number" 
            SortExpression="Number" />
        <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
        <asp:BoundField DataField="Name" HeaderText="Name" 
            SortExpression="Name" />

page.aspx.vb

    Dim tw As New System.IO.StringWriter()
    Dim hw As New System.Web.UI.HtmlTextWriter(tw)

    Dim dgGrid As New DetailsView()

    dgGrid.DataSource = SqlDataSource1

    hw.WriteLine("<b>Title here</b>")

    dgGrid.HeaderStyle.Font.Bold = True
    dgGrid.DataBind()
    dgGrid.RenderControl(hw)

    Response.AddHeader("content-disposition", "attachment;filename=ReportOuput.xls")
    Response.ContentType = "application/vnd.ms-excel"
    Me.EnableViewState = False
    Response.Write(tw.ToString())
    Response.End()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:35:51+00:00Added an answer on May 18, 2026 at 4:35 am

    The following code does the work (I think I was binding the DetailsView too soon. Programmers explain if possible, thank u)

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        Response.Clear()
        Response.Buffer = True
        Response.AddHeader("content-disposition", "attachment;filename=ReportOutput.xls")
        Response.Charset = ""
        Response.ContentType = "application/vnd.ms-excel"
    
        Dim tw As New System.IO.StringWriter()
        Dim hw As New System.Web.UI.HtmlTextWriter(tw)
    
        hw.WriteLine("<h3>Output Form</h3>")
        DetailsView1.DataSource = SqlDataSource1
        DetailsView1.DataBind()
        DetailsView1.RenderControl(hw)
        Dim style As String = "<style> .textmode { mso-number-format:\@; } </style>"
    
        Response.Write(style)
        Response.Output.Write(tw.ToString())
        Response.Flush()
        Response.End()
        end Sub
    

    In my DetailsView, I now can modify cells background colour, size, etc, example:

      <asp:TemplateField HeaderStyle-BorderColor="LightGray" ItemStyle-BorderColor="LightGray" HeaderStyle-BackColor="LightGray" ItemStyle-BackColor="LightGray" HeaderText="Personal Details"></asp:TemplateField>   
      <asp:BoundField DataField="Title" HeaderText="Dependants" ItemStyle-HorizontalAlign="Right" SortExpression="Dependants" />
    

    I can also modify text, colour, etc in my code behind, example:

     Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.DataBound
    If DetailsView1.Rows(12).Cells(1).Text = "False" Then
            DetailsView1.Rows(12).Cells(1).Text = "This is false"
        ElseIf DetailsView1.Rows(12).Cells(1).Text = "True" Then
            DetailsView1.Rows(12).Cells(1).Text = "This is true"
        End If
       end sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data like this: 1 2 3 4 5 9 2 6
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.