Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I would like to get a sample perl code to fill up the html input field by making use of a .xls file. The flow is like this.. I have page containing a "Go" button. Click on the "Go" button will call a perl program, that should read a .xls file record (first record) and fill up these data input fields of an html file. How can i do that? It will be helpful for me if anyone can provide sample code. -------------------------- First html:- test.html
<HTML><HEAD><TITLE> Test </TITLE></HEAD> <BODY> <form method="post" name="test" action="/cgi-bin/readxls.pl"> <input type="Submit" name="Go" value="Go"> </form> </BODY></HTML>
abc.xls file abc.xls file contain 3 fields say name, age and sex abc.xls file contain data as follows: Xavier 25 M Mary 22 F Result from .xls file will fillup in the following html file. result.html -----------
<HTML><HEAD><TITLE> Test </TITLE></HEAD> <BODY> Name: <input type="text" name="name" ><br> Age: <input type="text" name="age" ><br> Name: <input type="text" name="sex" ><br> </BODY></HTML>
Call test.html file and click on the "Go" button will call a perl program that will read first record (say Xavier, 25, M) from the abc.xls file and fillup the appropriate fields in the result.html and display in the browser. Hope i my questions is clear to all. I am waiting for the great help from the perl experts. Thanks Best Regards, Dan

Replies are listed 'Best First'.
Re: read xls file using Perl program
by meetraz (Hermit) on Dec 16, 2003 at 19:41 UTC
    You probably want Spreadsheet::ParseExcel if you are doing it on Linux.

    If you were doing it on NT, you could use Win32::OLE.

Re: read xls file using Perl program
by dragonchild (Archbishop) on Dec 17, 2003 at 03:10 UTC
    Another option would be to ask your teacher what s/he'd recommend.

    If you either already have or don't want to, some useful reading:

    The above modules are all you need to make what you want happen. Below are modules that can make your life easier ... if you're into that sort of thing

    Now, it sounds like you have another issue - you don't know what you want done. Well, you know what you need to have done, but you don't know how to do it. This isn't a Perl issue or a web issue - it's a thinking issue. Unless you are willing and able to think, you cannot program. Period.

    You have all the pieces, but I will bet you haven't put together a simple flowchart. You haven't laid out the sequence of events that need to occur in order to make this happen. You may not know the sequence of events. (Learn about how CGI works. Note - Perl and CGI are not the same thing. Perl does CGI, but so do a ton of other languages. For example, C++ does CGI on Unix quite nicely!)

    Once you have laid out the sequence of events and have learned how your tools work, then you are able to build what you're looking to do. Of course, if you waited until the last minute, you're up a creek without a paddle. Good luck!

    ------
    We are the carpenters and bricklayers of the Information Age.

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: read xls file using Perl program
by freddo411 (Chaplain) on Dec 16, 2003 at 17:43 UTC
    Your example code indicates that you want the perl program to be running on a web server. Please clarify what you want to do; Is the file you want to load on the server or on the client machine that is running the web browser?

    -------------------------------------
    Nothing is too wonderful to be true
    -- Michael Faraday

      Hi freddo411
      Yes ... Thankns for your comment. I want to run the perl program in web server. The xls,html and perl program should be kept in server. Need a perl program that work under Linux and output will be shown in the browser.
      Thanks
      Regards
      Dan
        You want to pre-populate these input fields with data from the web server side. The previous poster gave you a pointer to a way to read the data from an excel file. You might also save yourself some trouble and save the file as text formated as .csv or tab seperated data. In that case you can have perl easily read the file and parse the data into variables.

        Pre-populating an HTML for can be done using HTML::FillInForm. The code can be as simple as:

        ... code to read in or create your $page ... code to read in your excel data and format into a hashref called $ +dbrecord # fill in the user input forms with dbrecord data use HTML::FillInForm; my $fif = new HTML::FillInForm; my $out_page = $fif->fill( scalarref => \$page, fdat => $dbrecord);

        -------------------------------------
        Nothing is too wonderful to be true
        -- Michael Faraday