1 package SQL::Translator::Parser::Excel;
3 # -------------------------------------------------------------------
4 # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
5 # darren chamberlain <darren@cpan.org>,
6 # Chris Mungall <cjm@fruitfly.org>,
7 # Mike Mellilo <mmelillo@users.sourceforge.net>
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; version 2.
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 # -------------------------------------------------------------------
26 SQL::Translator::Parser::Excel - parser for Excel
31 use SQL::Translator::Parser::Excel;
33 my $translator = SQL::Translator->new;
34 $translator->parser("SQL::Translator::Parser::Excel");
38 Parses an Excel spreadsheet file for SQL::Translator. You can then
39 turn the data into a database tables or graphs.
44 use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
45 $DEBUG = 0 unless defined $DEBUG;
48 use Spreadsheet::ParseExcel;
50 use base qw(Exporter);
52 @EXPORT_OK = qw(parse);
54 # -------------------------------------------------------------------
56 my ( $translator, $data ) = @_;
65 my $tr = Spreadsheet::ParseExcel->new;
67 my $r = 1; # For now we will assume all column names are in the first row
71 # Mikey, what's going on here?
73 my @parsed = map { return $tr->{'Cells'}[$r][$c] } (
75 $c <= $tr->{'MaxCol'}; # Is "<=" right?
79 for ( my $i = 0; $i < @parsed; $i++ ) {
80 $parsed->{'table1'}->{'fields'}->{$parsed[$i]} = {
85 # Default datatype is 'char'
88 # default size is 8bits; something more reasonable?
94 # field field is the primary key
95 is_primary_key => ($i == 0) ? 1 : undef,
100 # Field 0 is primary key, by default, so add an index
101 for ($parsed->{'table1'}->{'indices'}->[0]) {
102 $_->{'type'} = 'primary_key';
103 $_->{'name'} = undef;
104 $_->{'fields'} = [ $parsed[0] ];
116 Mike Mellilo <mmelillo@users.sourceforge.net>,
117 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>
121 perl(1), Spreadsheet::ParseExcel.