User since
2004-08-24
5
Artikel
BenutzerIn
Hallo zusammen
Hab eine kurze Frage. Ist es möglich, Daten aus einer Excel Tabelle (Office XP) in eine vorhandene MySQL Datenbank zu importieren? Wenn ja, wie?
Wäre sehr dankbar für eine Antwort
Gruss
User since
2003-11-28
3645
Artikel
ModeratorIn
Man koennte z.B.
Spreadsheet::ParseExcel verwenden, um die Excel-Daten auszulesen.
Oder die Excel-Datei als CSV exportieren, dann
DBD::AnyData und
DBIx::Copy zusammen verwenden, um den Import nach MySQL zu machen.
User since
2003-08-04
14371
Artikel
ModeratorIn
Ich habe mal testweise was geschrieben, womit man ne Excel als CSV speichert...
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;
}
User since
2004-08-24
5
Artikel
BenutzerIn
Danke
Hat mir weitergeholfen, habs hinbekommen