Thread Exceldaten nach MySQL DB: Exceldaten in eine vorhandene MySQL DB (3 answers)
Opened by Nikolaj at 2004-08-24 12:46

renee
 2004-08-24 14:52
#32594 #32594
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Ich habe mal testweise was geschrieben, womit man ne Excel als CSV speichert...
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#! /usr/bin/perl

use strict;
use warnings;
use lib qw(./cpan/perllib);
use Spreadsheet::ParseExcel;

my $file = (-f $ARGV[0]) ? $ARGV[0] : print_error($ARGV[0]."is not a file");
my $home = -d $ARGV[1] ? $ARGV[1] : print_error($ARGV[1]."is not a directory");

print_error('wrong parameters','use') unless($file && $home);

my $xls = Spreadsheet::ParseExcel::Workbook->Parse($file) or print_error($!);
foreach my $workbook(@{$xls->{Worksheet}}){
my $csv = $home.'/'.$workbook.'.csv';
print "CSV: $csv\n";
open(W_CSV,">$csv") or print_error($csv." ".$!);
for(my $row = $workbook->{MinRow}; defined $workbook->{MaxRow} && $row <= $workbook->{MaxRow}; $row++){
my @values = ();
for(my $col = $workbook->{MinCol}; defined $workbook->{MaxCol} && $col <= $workbook->{MaxCol}; $col++){
my $cell = $workbook->{Cells}[$row][$col];
my $val = $cell ? $cell->Value : '';
push(@values, $val);
}
print W_CSV join(';',@values),"\n";
}
close W_CSV;
}

sub print_error{
print STDERR "Error: ",shift,"\n";
if(shift eq 'use'){
print qq~
Usage: $0 <excel_file> <output_path>

~;
}
exit -1;
}
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Exceldaten nach MySQL DB: Exceldaten in eine vorhandene MySQL DB