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

I'm new to this community/forum, so please forgive me if I miss any normal question protocols. I have not programmed in Perl in a couple of years, and the programming I have done has been pretty basic and related to CGI. I work for a university and have been asked to create an HTML form that will collect data via Perl into a Microsoft Excel file. Periodically--maybe every week--they will download this file and import it into an internal program that I have nothing to do with, then the file data will need to be cleared (emptied) and repeat, so on and so on. Anyone have any ideas of a basic way to do this? The data is not sensitive, so security is not a big issue. Thank you in advance, James Kennedy

Replies are listed 'Best First'.
Re: CGI form to Excel file
by samtregar (Abbot) on Jun 14, 2006 at 18:39 UTC
    Th easiest thing you can do is produce a CSV file which Excel can load. Text::CSV_XS is a great tool for the job. Slightly harder is to create a real Excel file using Spreadsheet::WriteExcel. That will let you create formulas, fill in multiple sheets, add formatting, etc.

    If you're also wondering about how to get started writing the CGI itself, I suggest you pick up a copy of O'Reilly's CGI Progamming with Perl book. It's a good introduction to the wide range of tools available.

    -sam

      Thanks for the quick reply. I'll take a look at Spreadsheet:WriteExcel. I've created text files before in Perl and separated them by delimiters like semi-colons, colons, etc. (I'm assuming Text::CSV XS is for something like this?), and I've also separately imported text files into Excel based on delimiters many times. Thanks, James Kennedy
        Text::CSV_XS is a module to create and parse CSV files very quickly, without skipping any of the hard stuff. By hard-stuff I mean proper quoting, escaping, dealing with cross-platform line-breaks (although sadly, it doesn't deal well with Mac line-breaks), etc.

        -sam

Re: CGI form to Excel file
by jeffa (Bishop) on Jun 14, 2006 at 18:49 UTC
Re: CGI form to Excel file
by InfiniteSilence (Curate) on Jun 14, 2006 at 19:50 UTC
    "HTML form that will collect data via Perl into a Microsoft Excel file..." So, essentially, you have been tasked with two jobs:
    • Collect data from multiple users via CGI
    • Produce an Excel report periodically (once a week it seems)
    Do you see how these are separate and distinct tasks that do not necessarily have to be coupled in the way you have specified? Your solution will be much more flexible if you look at the Excel requirement as a reporting requirement rather than as a mandate to use Excel for data storage. Using an RDBMS, for instance, will suit you far better and more efficiently for the CGI portion. You can then write something that reads from that into Excel or CSV or XML or whatever...

    Celebrate Intellectual Diversity

Re: CGI form to Excel file
by dragonchild (Archbishop) on Jun 14, 2006 at 20:41 UTC
    Excel::Template was designed for specifically this task.

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: CGI form to Excel file
by radiantmatrix (Parson) on Jun 14, 2006 at 19:56 UTC

    I'm new to this community/forum, so please forgive me if I miss any normal question protocols.

    There isn't exactly a protocol, per se, but How (Not) To Ask A Question would be a useful read for learning how to ask questions in such a way as to get a quality response.

    That said, I agree with the monk who mentions thinking about Excel as a reporting requirement. I suggest "collecting" the data into a database (see DBD::SQLite2 if you can't install an RDBMS on your server) or a CSV file (using Text::CSV_XS), and having a separate report-writer that creates the Excel file when it is needed.

    Depending on your requirements, a CSV file might be acceptable for download, as it opens directly in Excel without a hitch.

    <radiant.matrix>
    A collection of thoughts and links from the minds of geeks
    The Code that can be seen is not the true Code
    I haven't found a problem yet that can't be solved by a well-placed trebuchet
Re: CGI form to Excel file
by jamesmkennedy (Initiate) on Jun 15, 2006 at 00:50 UTC

    Thank you all for your quick responses. I signed up for another perl forum two days ago to ask this question and have still not received a response. You guys are great! I will consider your advice and begin investigating.

    Sincerely,

    James Kennedy