Excel worksheets in asp.net

Discussion in 'ASP .Net' started by DavidC, Mar 18, 2010.

  1. DavidC

    DavidC Guest

    I have a process to send data to Excel in a browser window from both a server
    control and via dataset code. I would like to create multiple worksheets
    (tabs in lower part of Excel spreadsheet) in one xls file. Is that possible?
    Below is a sample of code I am using to dump to Excel. Thanks.

    Sub ExportDataSetToExcel(ByVal Source As Object, ByVal E As EventArgs)
    strExcelSQL = "mc_selPeopleSearchHomeExcel"
    Response.Clear()
    Response.ContentType = "application/vnd.excel"
    Response.Charset = "us-ascii"
    Response.AddHeader("content-disposition",
    "attachment;filename=search.xls")

    Dim gv As New GridView
    Using conFileData As SqlConnection = New
    SqlConnection(DBClass.GetCoreConnectionString)
    conFileData.Open()

    Dim ddl As DropDownList =
    Page.Master.FindControl("ddlProgramCode")
    Dim intProgramID As Int32 = Convert.ToInt32(ddl.SelectedValue)
    Dim tb As TextBox = Page.Master.FindControl("txtFindText")

    'Get records based on sql
    Dim cmdSel As SqlCommand = New SqlCommand(strExcelSQL,
    conFileData)
    cmdSel.CommandType = Data.CommandType.StoredProcedure

    Dim parameter As New SqlParameter()
    parameter.ParameterName = "@ProgramID"
    parameter.SqlDbType = Data.SqlDbType.Int
    parameter.Direction = Data.ParameterDirection.Input
    parameter.Value = intProgramID
    cmdSel.Parameters.Add(parameter)

    parameter = New SqlParameter()
    ...
    ...

    Dim dtr As SqlDataReader
    dtr = cmdSel.ExecuteReader()
    gv.DataSource = dtr
    gv.DataBind()
    dtr.Close()

    End Using

    Dim sw As New StringWriter()
    Dim htw As New System.Web.UI.HtmlTextWriter(sw)
    EnableViewState = False
    gv.RenderControl(htw)
    Response.Write(sw.ToString())
    Response.End()
    End Sub
    --
    David
    DavidC, Mar 18, 2010
    #1
    1. Advertising

  2. Mark Rae [MVP], Mar 18, 2010
    #2
    1. Advertising

  3. DavidC

    Andy O'Neill Guest

    "DavidC" <> wrote in message
    news:...
    >I have a process to send data to Excel in a browser window from both a
    >server
    > control and via dataset code. I would like to create multiple worksheets
    > (tabs in lower part of Excel spreadsheet) in one xls file. Is that
    > possible?


    Yes, but using a different technique.
    You can do this with xslt.
    Andy O'Neill, Mar 19, 2010
    #3
  4. DavidC

    DavidC Guest

    "Andy O'Neill" wrote:

    >
    > "DavidC" <> wrote in message
    > news:...
    > >I have a process to send data to Excel in a browser window from both a
    > >server
    > > control and via dataset code. I would like to create multiple worksheets
    > > (tabs in lower part of Excel spreadsheet) in one xls file. Is that
    > > possible?

    >
    > Yes, but using a different technique.
    > You can do this with xslt.
    >
    > .
    >

    Can you point me to where I can find out more about this? Thanks.

    David
    DavidC, Mar 19, 2010
    #4
  5. DavidC

    Andy O'Neill Guest

    "DavidC" <> wrote in message
    news:...
    > "Andy O'Neill" wrote:
    >
    >>
    >> "DavidC" <> wrote in message
    >> news:...
    >> >I have a process to send data to Excel in a browser window from both a
    >> >server
    >> > control and via dataset code. I would like to create multiple
    >> > worksheets
    >> > (tabs in lower part of Excel spreadsheet) in one xls file. Is that
    >> > possible?

    >>
    >> Yes, but using a different technique.
    >> You can do this with xslt.
    >>
    >> .
    >>

    > Can you point me to where I can find out more about this? Thanks.
    >
    > David


    If you google on
    dataset xslt excel

    There are a number of examples.
    For all your formatting, the best way is to create an excel spreadsheet like
    you want.
    Save it as xml and take a look at what you get.
    Andy O'Neill, Mar 21, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nik
    Replies:
    1
    Views:
    1,214
    ardent.alan
    Mar 21, 2012
  2. appu
    Replies:
    1
    Views:
    552
    Mark Rae
    Jan 5, 2007
  3. =?Utf-8?B?RGF2ZQ==?=

    Exporting to multiple excel worksheets from asp.net?

    =?Utf-8?B?RGF2ZQ==?=, Jan 26, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    2,195
    Mark Rae
    Jan 26, 2007
  4. Jona
    Replies:
    2
    Views:
    440
    Victor Bazarov
    Jul 6, 2007
Loading...

Share This Page