Data from form to excel

Discussion in 'HTML & Website Design' started by Quartz, Jan 12, 2008.

  1. #1
    What do you think would be the easiest way to data from a form saved to an excel documents when submit button is pressed ?
     
    Quartz, Jan 12, 2008 IP
  2. Veej

    Veej Active Member

    Messages:
    364
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Save the form data as a CSV file and import that into Excel perhaps?
     
    Veej, Jan 12, 2008 IP
  3. RockyMtnHi

    RockyMtnHi Active Member

    Messages:
    211
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    You can change the header of the page that you post to and write out the page as an Excel file. The content should be written out as if you are creating a normal html file, but it actually opens in Excel. Here is the code I use in ASP to do it:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <!--#include file="21st_common.asp" -->
    <%
    if trim(session("CustomerCompanyId")) = "" then
    response.redirect "index.asp"
    end if

    ' open as an excel spreadsheet if excel=true
    if request.querystring("excel") = "true" then
    'NOTE: MS Excel 2000 SP1 is required to render the HTML of this page into an Excel Spreadsheet
    Response.Clear
    Response.ContentType = "application/vnd.ms-excel"
    Response.AddHeader "Content-Disposition", "attachment; filename=MultiMgmtReport.xls"
    end if
    %>
     
    RockyMtnHi, Jan 12, 2008 IP
  4. whosedomain

    whosedomain Active Member

    Messages:
    257
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #4
    how about php page, can you tell me how to do?
     
    whosedomain, Jan 13, 2008 IP
  5. RockyMtnHi

    RockyMtnHi Active Member

    Messages:
    211
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    Don't have the code for it but I'd probably do a Google search for "php contenttype addheader excel" or something like that.
     
    RockyMtnHi, Jan 13, 2008 IP
  6. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The above code doesnt actually "output" Excel but tells the browser to open the page in Excel so if the end user doesnt have Excel or an Excel viewer installed then they wont be able to use it where as a true conversion would at least allow them to save it as a true Excel file.

    A CSV file is possibly the better route on the basis it is a universal file type that all computers will be able to open as even a basic text editor can open it but Excel also have native support to open them (you dont have to import)

    To output a true Excel file isnt the easiest of things to do, whilst we can do it using .Net I know a fairly good php programmer gave up on the project when they attempted to do it.
     
    AstarothSolutions, Jan 13, 2008 IP