#!/usr/bin/perl
#===============================
# mysql to excel
# lastmodify at
# copyright by hoowa
#=============================
use strict; #嚴格語法檢測
use DBI; #數據庫引擎
use Unicode::Map; #Unicode引擎
#use Spreadsheet::WriteExcel; #Excel報表引擎
use Spreadsheet::WriteExcel::Big; #大文件Excel報表引擎
my $hostname=
my $username=
my $password=
my $dbname=
my $trans_compress=
$|=
my @cols=(
#解析來內容
if ($#ARGV !=
print qq~syntax: my
~;
exit;
}
$ARGV[
warn qq~
mysql to excel
by hoowa
=====================
sql: $ARGV[
~;
my $dbh =
DBI
database=$dbname;host=$hostname
my $sth = $dbh
my $rows = $sth
warn
my @cols_name = @{$sth
if ($#cols_name > $#cols) {
exit;
}
warn
#生成GB
my $map = Unicode::Map
#產生報表
my $report = Spreadsheet::WriteExcel::Big
#創建報表的工作表
my $sheet = $report
#創建格式
my $title_style = $report
#初始化數據指針
my $sheet_col =
#創建表格
for (my $i=
$sheet
$sheet
}
$sheet
while (my @row = $sth
$sheet_col++;
for (my $i=
next if ($row[$i] eq
$sheet
}
}
warn
#結束
END {
$report
$dbh
}
From:http://tw.wingwit.com/Article/program/MySQL/201311/29338.html