Export datalist to Excel - css format is lost!

Discussion in 'ASP .Net' started by staeri@gmail.com, Mar 14, 2006.

  1. Guest

    I'm trying to export a datalist to Excel with this code:

    Response.Clear()
    Response.Buffer = True
    Response.Charset = ""
    Response.ContentType = "application/vnd.ms-excel"
    Me.EnableViewState = False
    Dim sw As StringWriter = New StringWriter()
    Dim hw As HtmlTextWriter = New HtmlTextWriter(sw)
    DataList1.RenderControl(hw)
    Response.Write(sw.ToString())
    Response.End()

    Unfortunately all the format set from css is lost. Is there a way to
    get around this?

    Regards,

    S
    , Mar 14, 2006
    #1
    1. Advertising

  2. I'm working on a classic ASP page that will invoke the Excel plugin when
    using IE. Here's how I start it.
    Response.ContentType = "application/vnd.ms-excel"
    Response.Charset = ""
    Response.CacheControl = "no-cache"
    Response.AddHeader "Pragma", "no-cache"
    Response.Expires = -1

    After that I do a bunch of code to get data from a database.Then I just
    construct an HTML table and use a style block for formating as in

    <style>
    table,td{border-style:solid;border-color:#C0C0C0;border-width:thin}
    .title{font-weight:bold}
    .label{font-weight:bold;padding-left:1em;vertical-align:middle}
    .colhead{font-weight:bold;text-align:center;vertical-align:middle}
    .participants{vertical-align:middle;padding-left:1em;height:24}
    .badge{vertical-align:middle;text-align:right}
    .total{font-weight:bold;vertical-align:middle;padding-left:6em;height:24}
    </style>

    Here's a snippet of the html coding

    <tr>
    <td class="label">Course Name:</td>
    <td colspan=2 class="title"><%=strClassName%></td></tr>
    <tr>
    <td class="label">Dates:</td>
    <td colspan=2>
    <%=datStartDate%> to <%=datEndDate%><br></td></tr>

    this is all working fine.

    my problem is how to force a page break.

    --
    no place like 127.0.0.1


    "" wrote:

    > I'm trying to export a datalist to Excel with this code:
    >
    > Response.Clear()
    > Response.Buffer = True
    > Response.Charset = ""
    > Response.ContentType = "application/vnd.ms-excel"
    > Me.EnableViewState = False
    > Dim sw As StringWriter = New StringWriter()
    > Dim hw As HtmlTextWriter = New HtmlTextWriter(sw)
    > DataList1.RenderControl(hw)
    > Response.Write(sw.ToString())
    > Response.End()
    >
    > Unfortunately all the format set from css is lost. Is there a way to
    > get around this?
    >
    > Regards,
    >
    > S
    >
    >
    =?Utf-8?B?dmJwaGls?=, Apr 5, 2006
    #2
    1. Advertising

  3. Dracs Guest

    what did u do?


    wrote:
    > *I'm trying to export a datalist to Excel with this code:
    >
    > Response.Clear()
    > Response.Buffer = True
    > Response.Charset = ""
    > Response.ContentType = "application/vnd.ms-excel"
    > Me.EnableViewState = False
    > Dim sw As StringWriter = New StringWriter()
    > Dim hw As HtmlTextWriter = New HtmlTextWriter(sw)
    > DataList1.RenderControl(hw)
    > Response.Write(sw.ToString())
    > Response.End()
    >
    > Unfortunately all the format set from css is lost. Is there a way to
    > get around this?
    >
    > Regards,
    >
    > S



    -
    Drac
    -----------------------------------------------------------------------
    Posted via http://www.codecomments.co
    -----------------------------------------------------------------------
    Dracs, May 23, 2006
    #3
  4. Dracs
    see Steve's article http://steveorr.net/articles/ExcelExport.aspx
    Patrick

    "Dracs" <> wrote in message
    news:D...
    >
    > what did u do?
    >
    >
    > wrote:
    >> *I'm trying to export a datalist to Excel with this code:
    >>
    >> Response.Clear()
    >> Response.Buffer = True
    >> Response.Charset = ""
    >> Response.ContentType = "application/vnd.ms-excel"
    >> Me.EnableViewState = False
    >> Dim sw As StringWriter = New StringWriter()
    >> Dim hw As HtmlTextWriter = New HtmlTextWriter(sw)
    >> DataList1.RenderControl(hw)
    >> Response.Write(sw.ToString())
    >> Response.End()
    >>
    >> Unfortunately all the format set from css is lost. Is there a way to
    >> get around this?
    >>
    >> Regards,
    >>
    >> S *

    >
    >
    >
    > --
    > Dracs
    > ------------------------------------------------------------------------
    > Posted via http://www.codecomments.com
    > ------------------------------------------------------------------------
    >
    Patrick.O.Ige, May 24, 2006
    #4
    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. =?Utf-8?B?RGF2aWQgVmFsbGU=?=

    Invalid export DLL or export format

    =?Utf-8?B?RGF2aWQgVmFsbGU=?=, Oct 29, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    3,617
    =?Utf-8?B?RGF2aWQgVmFsbGU=?=
    Oct 29, 2003
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,868
  3. Peter
    Replies:
    1
    Views:
    10,056
    Steve C. Orr [MVP, MCSD]
    Nov 9, 2004
  4. Julien
    Replies:
    1
    Views:
    13,820
    Steve C. Orr [MVP, MCSD]
    Feb 28, 2005
  5. Replies:
    2
    Views:
    3,134
    Jacob
    Mar 7, 2006
Loading...

Share This Page