package SQL::Translator::Parser::Excel;
-# -------------------------------------------------------------------
-# $Id: Excel.pm,v 1.9 2003-10-09 21:49:53 kycl4rk Exp $
-# -------------------------------------------------------------------
-# Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>,
-# darren chamberlain <darren@cpan.org>,
-# Chris Mungall <cjm@fruitfly.org>,
-# Mike Mellilo <mmelillo@users.sourceforge.net>
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; version 2.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307 USA
-# -------------------------------------------------------------------
-
=head1 NAME
SQL::Translator::Parser::Excel - parser for Excel
=head1 SYNOPSIS
use SQL::Translator;
- use SQL::Translator::Parser::Excel;
my $translator = SQL::Translator->new;
- $translator->parser("SQL::Translator::Parser::Excel");
+ $translator->parser('Excel');
=head1 DESCRIPTION
-Parses an Excel spreadsheet file for SQL::Translator. You can then
-turn the data into a database tables or graphs.
+Parses an Excel spreadsheet file using Spreadsheet::ParseExcel.
=head1 OPTIONS
=cut
use strict;
-use vars qw($DEBUG $VERSION @EXPORT_OK);
+use warnings;
+our ($DEBUG, @EXPORT_OK);
$DEBUG = 0 unless defined $DEBUG;
-$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/;
+our $VERSION = '1.59';
use Spreadsheet::ParseExcel;
use Exporter;
#
# If directed, look at every field's values to guess size and type.
#
- unless (
+ unless (
defined $args->{'scan_fields'} &&
$args->{'scan_fields'} == 0
) {
for(
my $iR = $ws->{'MinRow'} == 0 ? 1 : $ws->{'MinRow'};
- defined $ws->{'MaxRow'} && $iR <= $ws->{'MaxRow'};
+ defined $ws->{'MaxRow'} && $iR <= $ws->{'MaxRow'};
$iR++
) {
- for (
+ for (
my $iC = $ws->{'MinCol'};
- defined $ws->{'MaxCol'} && $iC <= $ws->{'MaxCol'};
+ defined $ws->{'MaxCol'} && $iC <= $ws->{'MaxCol'};
$iC++
) {
my $field = $field_names[ $iC ];
if ( $data =~ /^-?\d+$/ ) {
$type = 'integer';
}
- elsif (
- $data =~ /^-?[,\d]+\.[\d+]?$/
+ elsif (
+ $data =~ /^-?[,\d]+\.[\d+]?$/
||
- $data =~ /^-?[,\d]+?\.\d+$/
+ $data =~ /^-?[,\d]+?\.\d+$/
||
- $data =~ /^-?\.\d+$/
+ $data =~ /^-?\.\d+$/
) {
$type = 'float';
- my ( $w, $d ) = map { s/,//g; $_ } split( /\./, $data );
- $size = [ length $w, length $d ];
+ my ( $w, $d ) =
+ map { s/,//g; length $_ || 1 }
+ split( /\./, $data )
+ ;
+ $size = [ $w + $d, $d ];
}
else {
$type = 'char';
}
for my $field ( keys %field_info ) {
- my $size = $field_info{ $field }{'size'} || 0;
- my $data_type =
- $field_info{ $field }{'char'} ? 'char' :
+ my $size = $field_info{ $field }{'size'} || [ 1 ];
+ my $data_type =
+ $field_info{ $field }{'char'} ? 'char' :
$field_info{ $field }{'float'} ? 'float' :
$field_info{ $field }{'integer'} ? 'integer' : 'char';
return 1;
}
-# -------------------------------------------------------------------
sub ET_to_ST {
my $et = shift;
$ET_to_ST{$et} || $ET_to_ST{'Text'};