How to export to Excel while including Javascript output?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • damicomj
    New Member
    • Sep 2010
    • 34

    How to export to Excel while including Javascript output?

    I didn't know whether to put this in the ASP section or Javascript section. Please move it into the appropriate section if this isn't correct.

    I am trying to export one of my pages to an Excel document. I can do the export successfully. However, my divider, which contains the javascript class (simpleCart_ite ms) is not being transferred during the export.

    Code:
    <%	
        Response.Buffer = true
        Response.ContentType = "application/vnd.ms-excel; name='excel'"
    %>
    
    <html xmlns:x="urn:schemas-microsoft-com:office:excel">
    <head>
    
    <link rel="stylesheet" type="text/css" href="cart.css" />
    <SCRIPT src="../simpleCart.js" type=text/javascript></SCRIPT>
    <script type="text/javascript">
    	simpleCart.currency = USD;
    	simpleCart.cartHeaders = ["Name" , "Color", "Price", "Quantity", "Total",];
    </script>
    </head>
    
    <body>
    
    <table width="950" id="table1" cellspacing="0" cellpadding="0" style="border-bottom: 1px black solid;">
    	<tr>
    		<td width=260px><b>Item</b></td>
    		<td width=107px align=center><b>Color</b></td>
    		<td width=127px align=center><b>Price</b></td>
    		<td width=40px align=center><b>Quantity</b></td>
    		<td width=138px align=center><b>Subtotal</b></td>
    		<td width=276px>&nbsp;</td>
    	</tr>
    </table>
    <br>
    
    <div class="simpleCart_items" style="border-bottom: 1px black solid; float:left;">
    </div>
    
    </body>
    </html>
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Javascript is client side. If you are exporting via ASP you will be exporting the document before the javascript has been called.

    Comment

    • damicomj
      New Member
      • Sep 2010
      • 34

      #3
      Very good point. Do you have a suggestion? Thank you.

      Comment

      • rnd me
        Recognized Expert Contributor
        • Jun 2007
        • 427

        #4
        Originally posted by damicomj
        Very good point. Do you have a suggestion? Thank you.
        yes, run the export from the browser, not from the server. that way, all the values are in the right place as expected.

        you can use activeX excel control, or generate a .csv file by iterating the table cells once the data loads. you can bounce the csv off of your server by .write()ing a post variable from the submit.

        in newer browsers, ie8+ included, you can even serve the csv directly from javascript (without a server) using a dataURL.

        Comment

        Working...