#!perl -w use warnings; use strict; use Template; use Spreadsheet::ParseExcel; use Data::Dumper; ## define the xml template here my $xmltemplate = "learning.xtt"; ## directory to write xml files to my $write_directory = "xml/"; my $rand = rand($$); my $outputname = "$rand.xml"; ## set up the output settings and such my $xmlfile = Template->new({ OUTPUT_PATH => "xml" }) || die $Template::ERROR; my $oExcel = new Spreadsheet::ParseExcel; my $filename = $ARGV[0]; chomp $filename; unless (-e $filename) { print "Can't find file $filename"; exit ; } ## read in the spread sheet my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($filename); ## begin conversion... my @raw_data = (); # excel data... foreach my $oWkS (@{$oBook->{Worksheet}}) { next unless defined $oWkS->{MinRow} and defined $oWkS->{MaxRow}; for my $iR ($oWkS->{MinRow} .. $oWkS->{MaxRow}) { for my $iC ($oWkS->{MinCol} .. $oWkS->{MaxCol}) { my %raw_data; my $oWkC = $oWkS->{Cells}[$iR][$iC]; next if ! defined $oWkC; my @columns = qw( id category code title group sub_group sequence role_mandatory role_recommended role_optional url modality length ); @raw_data{ @columns } = map { $oWkC->Value } @columns; } } } ## process the template print "Converting...\n\n"; print "Writing to file...\n\n"; open FH, ">", "debug.txt"; print FH Dumper (\@raw_data); close FH; #$xmlfile->process( $xmltemplate, # { # xml => \@excel_data # }, # $outputname ## for test purposes #) || die $Template::ERROR; print "Done!\n\n"; #### [% FOREACH xml %] [% id %] [% category %] [% code %] [% title %] [% group %] [% sub_group %] [% sequence %] [% role_mandatory %] [% role_recommended %] [% role_optional %] [% url %] [% modality %] [% length %] [% END %]