[2990] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15872] | 3 | # ExcelPlugin.pm -- plugin for importing Microsoft Excel files.
|
---|
[2990] | 4 | # (currently only versions 95 and 97)
|
---|
| 5 | #
|
---|
| 6 | # A component of the Greenstone digital library software
|
---|
| 7 | # from the New Zealand Digital Library Project at the
|
---|
| 8 | # University of Waikato, New Zealand.
|
---|
| 9 | #
|
---|
| 10 | # Copyright (C) 2002 New Zealand Digital Library Project
|
---|
| 11 | #
|
---|
| 12 | # This program is free software; you can redistribute it and/or modify
|
---|
| 13 | # it under the terms of the GNU General Public License as published by
|
---|
| 14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | # (at your option) any later version.
|
---|
| 16 | #
|
---|
| 17 | # This program is distributed in the hope that it will be useful,
|
---|
| 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | # GNU General Public License for more details.
|
---|
| 21 | #
|
---|
| 22 | # You should have received a copy of the GNU General Public License
|
---|
| 23 | # along with this program; if not, write to the Free Software
|
---|
| 24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 25 | #
|
---|
| 26 | ###########################################################################
|
---|
| 27 |
|
---|
[15872] | 28 | package ExcelPlugin;
|
---|
[2990] | 29 |
|
---|
[15872] | 30 | use ConvertBinaryFile;
|
---|
[10254] | 31 | use strict;
|
---|
| 32 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[2990] | 33 |
|
---|
| 34 | sub BEGIN {
|
---|
[15872] | 35 | @ExcelPlugin::ISA = ('ConvertBinaryFile');
|
---|
[2990] | 36 | }
|
---|
| 37 |
|
---|
[6408] | 38 | my $arguments =
|
---|
| 39 | [ { 'name' => "process_exp",
|
---|
[15872] | 40 | 'desc' => "{BasePlugin.process_exp}",
|
---|
[6408] | 41 | 'type' => "regexp",
|
---|
| 42 | 'reqd' => "no",
|
---|
| 43 | 'deft' => &get_default_process_exp() }
|
---|
| 44 | ];
|
---|
| 45 |
|
---|
[15872] | 46 | my $options = { 'name' => "ExcelPlugin",
|
---|
| 47 | 'desc' => "{ExcelPlugin.desc}",
|
---|
[6408] | 48 | 'abstract' => "no",
|
---|
| 49 | 'inherits' => "yes",
|
---|
[15114] | 50 | 'srcreplaceable' => "yes", # Source docs in Excel format can be replaced with GS-generated html
|
---|
[6408] | 51 | 'args' => $arguments };
|
---|
[4744] | 52 |
|
---|
[2990] | 53 | sub new {
|
---|
[10218] | 54 | my ($class) = shift (@_);
|
---|
| 55 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 56 | push(@$pluginlist, $class);
|
---|
[2990] | 57 |
|
---|
[15918] | 58 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 59 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[10424] | 60 |
|
---|
[15872] | 61 | my $self = new ConvertBinaryFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[2990] | 62 |
|
---|
[10580] | 63 | if ($self->{'info_only'}) {
|
---|
| 64 | # don't worry about any options etc
|
---|
| 65 | return bless $self, $class;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[15872] | 68 | $self->{'filename_extension'} = "xls";
|
---|
| 69 | $self->{'file_type'} = "Excel";
|
---|
| 70 |
|
---|
[10424] | 71 | my $secondary_plugin_options = $self->{'secondary_plugin_options'};
|
---|
[15872] | 72 | if (!defined $secondary_plugin_options->{'HTMLPlugin'}) {
|
---|
| 73 | $secondary_plugin_options->{'HTMLPlugin'} = [];
|
---|
[10424] | 74 | }
|
---|
[15872] | 75 | my $html_options = $secondary_plugin_options->{'HTMLPlugin'};
|
---|
[10424] | 76 |
|
---|
| 77 | push(@$html_options, "-input_encoding", "utf8");
|
---|
[12834] | 78 | push(@$html_options,"-extract_language") if $self->{'extract_language'};
|
---|
[10270] | 79 | $self = bless $self, $class;
|
---|
[10424] | 80 |
|
---|
| 81 | $self->load_secondary_plugins($class,$secondary_plugin_options,$hashArgOptLists);
|
---|
| 82 | return bless $self;
|
---|
[2990] | 83 | }
|
---|
| 84 |
|
---|
[15872] | 85 | sub convert_post_process_old
|
---|
[10465] | 86 | {
|
---|
| 87 | my $self = shift (@_);
|
---|
| 88 | my ($conv_filename) = @_;
|
---|
| 89 |
|
---|
| 90 | my $outhandle=$self->{'outhandle'};
|
---|
| 91 |
|
---|
| 92 | my ($language, $encoding) = $self->textcat_get_language_encoding ($conv_filename);
|
---|
| 93 |
|
---|
| 94 | # read in file ($text will be in utf8)
|
---|
| 95 | my $text = "";
|
---|
| 96 | $self->read_file ($conv_filename, $encoding, $language, \$text);
|
---|
| 97 |
|
---|
| 98 | # turn any high bytes that aren't valid utf-8 into utf-8.
|
---|
| 99 | #unicode::ensure_utf8(\$text);
|
---|
| 100 |
|
---|
| 101 | # Write it out again!
|
---|
| 102 | #$self->utf8_write_file (\$text, $conv_filename);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[2990] | 105 | sub get_default_process_exp {
|
---|
| 106 | my $self = shift (@_);
|
---|
| 107 | return q^(?i)\.xls$^;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | 1;
|
---|