• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1003
  • Last Modified:

write to existing Excel file using Perl under FreeBSD + Perl 5.005_03

I have an existing Excel template file, and I would like to update it via web form.

How can this be done?
0
jay28lee
Asked:
jay28lee
  • 2
1 Solution
 
Perl_DiverCommented:
Are you using an XML file for the template? You could probably use XML::Simple to read the XML file and get it into a CGI form you can use to update it with once again useing XML::Simple. Then you can possibly use the Excel::Template module to create the excel file.

http://search.cpan.org/author/GRANTM/XML-Simple-2.14/lib/XML/Simple.pm
http://search.cpan.org/author/RKINYON/Excel-Template-0.25/lib/Excel/Template.pm
0
 
jay28leeAuthor Commented:
Is there a simple example coding of actual usage that you can show me?

I'm not familiar with these modules.
0
 
Perl_DiverCommented:
Both of the module documentations have code examples. If you don't actually need to create the excel file from the template at the time of the update then there is no need to use the Excel::Templat module at all. I'll use the example from the XML::Simple module, the xml file:

foo.xml

<config logdir="/var/log/foo/" debugfile="/tmp/foo.debug">
  <server name="sahara" osname="solaris" osversion="2.6">
    <address>10.0.0.101</address>
    <address>10.0.1.101</address>
  </server>
  <server name="gobi" osname="irix" osversion="6.5">
    <address>10.0.0.102</address>
  </server>
  <server name="kalahari" osname="linux" osversion="2.0.34">
    <address>10.0.0.103</address>
    <address>10.0.1.103</address>
  </server>
</config>

the outline of a script to get the file into a form:

foo.pl

#!perl
use strict;
use warnings;
use CGI;
use XML::Simple;
#use Data::Dumper;
my $q = new CGI;
my $config = XMLin();
my @fields = qw(logdir debugfile);

print $q->header,
      $q->start_html,
      $q->start_form(-action => 'update.pl');
foreach my $fields (@fields) {
   print "$fields: ",
   $q->textfield(-name=>$fields,
                       -default=>$config->{$fields},
                       -size=>50,
                       -maxlength=>80),
   '<br />';  
}
print $q->submit(),
            $q->end_form,
            $q->end_html;

then update.pl gets the form data and reopens the xml file, plugs the new values into the appropriate variables, and saves the data back to the xml file using the XMLout() function. Hope that gets you started.  

***I wish this forum had a preview option***
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now