| 1 | use DBI; | ||
| 2 | use DBI::Dump; | ||
| 3 | |||
| 4 | my $dbh = DBI->connect(...); | ||
| 5 | |||
| 6 | my $sth = $dbh->prepare("select * from users"); | ||
| 7 | |||
| 8 | $sth->execute(); | ||
| 9 | |||
| 10 | my $exceldb = DBIx::Dump->new(); | ||
| 11 | |||
| 12 | $exceldb->dump('format' => 'excel', 'output' => 'db2.xls', 'sth' => $sth, | ||
| 13 | 'eventHandler' => \&handler); | ||
| 14 | |||
| 15 | my $count = 0; | ||
| 16 | sub handler | ||
| 17 | { | ||
| 18 | my ($self, $data, $colName, $row) = @_; | ||
| 19 | |||
| 20 | my $format; | ||
| 21 | if ($count == 0) | ||
| 22 | { | ||
| 23 | $format = $self->{Generator}->addformat(); # Add a format | ||
| 24 | $format->set_bold(); | ||
| 25 | $format->set_color('red'); | ||
| 26 | $format->set_align('center'); | ||
| 27 | $self->{excelFormat} = $format; | ||
| 28 | } | ||
| 29 | $count++; | ||
| 30 | |||
| 31 | if ($row == 2) | ||
| 32 | { | ||
| 33 | $self->{excelFormat} = undef; | ||
| 34 | $format = $self->{Generator}->addformat(); # Add a format | ||
| 35 | $format->set_num_format(0x0f); | ||
| 36 | } | ||
| 37 | |||
| 38 | if ($row > 1 && $colName == 'ACQUISITION DATE') | ||
| 39 | { | ||
| 40 | $self->{excelFormat} = $format; | ||
| 41 | } | ||
| 42 | elsif ($row > 1) | ||
| 43 | { | ||
| 44 | $self->{excelFormat} = undef; | ||
| 45 | } | ||
| 46 | } | ||
| 47 |