Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

HTML table to excel or pdf document

Options
  • 15-02-2008 10:15am
    #1
    Registered Users Posts: 17,441 ✭✭✭✭


    Somewhat limited knowledge so forgive me if this is simple. I have a small asp driven web front end that pulls data from a database. Any calls to the database tend to be along the lines of all data between two dates. The calls are outputted to a html table. I would like to include an option whereby this output that be exported to an excel spreadsheet and downloaded. Outputting in PDF would be handy too. Any suggestions?

    Cheers for any help ye can offer.


Comments

  • Registered Users Posts: 3,594 ✭✭✭forbairt


    my suggestion would be to ...
    Output it into comma delimited text file
    (you're currently placing it into td content td ...
    output it with content,content,... or similar maybe with "'s thrown in ...

    Excel can import this file quite easily ...

    Of course if you want to start looking into COM (or whatever its called these days) and putting it into an excel file directly thats different.

    As to the PDFing ... create a pdf of it ? :D
    something like http://www.asppdf.com/


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Edit:- Crap, should read better - its ASP sorry. Thought PHP


  • Moderators, Music Moderators Posts: 23,359 Mod ✭✭✭✭feylya


    ASP can write directly to Excel using VBscript.

    http://www.serverwatch.com/tutorials/article.php/1493331

    Should be able to come up with something from that.


  • Registered Users Posts: 413 ✭✭ianhobo


    If you want your server to automatically create pdfs for you, you should be looking into xsl translations (xslt), specifically xsl-fo (formatting objects)

    Often used by data driven websites to provide both html content and/or pdf
    The data usually starts off in xml and is translated appropriately to either html of pdf

    The most popular/free implementations are for Java/Apache though, so obviously that wont mix with you asp.

    While this probably won't help you with your asp, there is some good general info here, but again its for an apache server object
    http://www.ibm.com/developerworks/edu/x-dw-xxslfo-i.html


  • Registered Users Posts: 413 ✭✭ianhobo


    If you ever go dot Net, you might be able to use this.
    It's a pdf server control

    http://sourceforge.net/projects/npdf/


  • Advertisement
  • Registered Users Posts: 17,441 ✭✭✭✭jesus_thats_gre


    Cheers lads


  • Registered Users Posts: 2,835 ✭✭✭StickyMcGinty


    for a quick way to export to excel, just change the content type at the top of the html page

    The browser will recognise it as an excel file and prompt you to save it to disk. I used to use it as a handy way of dumping a MsSQL db onto an excel file

    http://www.designdetector.com/archives/05/07/HTMLToExcelTheEasyWay.php


  • Registered Users Posts: 1,045 ✭✭✭Bluefrog


    Open up Excel and put headings in sheet1 for your data headings. Format the sheet as you want and add some sample data (a row or 2 will do) then save it off as an xml file. If you look at the XML souce in a text editor you'll see that just as in a html table, excel xml describes the sample data in columns and rows so you won't have to do much to output that xml via an asp script and just as you would with a HTML table, populate row in the XML dymanically with a loop. Build the xml string before outputting it, set your content type in the headers for the page to application/excel and output your XML string and your browser should see that it's an excel file being downloaded and prompt you to open in excel or save to disk.

    It's a similar idea to producing CSV - the issue with CSV is that you lose formatting and data types whereas you can preserve these in XML. This will only work for Excel XP+ however.

    As for the PDF I'd suggest looking for an open-source library but finding one for a Microsoft platform will be (as has been said) challenging.


Advertisement