MySQL導(dǎo)出 XLS 數(shù)據(jù)庫工具的實(shí)際操作
以下的文章主要介紹的是從MySQL導(dǎo)出 XLS 數(shù)據(jù)庫工具的介紹,XLS 數(shù)據(jù)庫工具之所以能在很短的時(shí)間內(nèi)被人們廣泛的應(yīng)用,原因也是因?yàn)樗?dú)特的功能。以下的文章主要介紹的是MySQL導(dǎo)出 XLS 數(shù)據(jù)庫工具的實(shí)際應(yīng)用。
- warn "write to: $ARGV[0]/n";
生成GB2312編碼系統(tǒng)
- my $map = Unicode::Map->new("gb2312");
產(chǎn)生報(bào)表
my $report = Spreadsheet::WriteExcel::Big->new("$ARGV[0]") || die "不能生成報(bào)表文件:$!";
創(chuàng)建報(bào)表的工作表
- my $sheet = $report->add_worksheet('data_report');
創(chuàng)建格式
- my $title_style = $report->add_format(); $title_style->set_size(11); $title_style->set_bold(); $title_style->set_align('center');
初始化數(shù)據(jù)指針
- my $sheet_col = 0;
從MySQL中導(dǎo)出XLS數(shù)據(jù)庫工具中創(chuàng)建表格
- for (my $i=0;$i<=$cols_name ;$i++) {
- $sheet->set_column($cols[$i], length($cols_name[$i])+4);
- $sheet->write_unicode($sheet_col,$i,$map->to_unicode($cols_name[$i]),$title_style);
- }
$sheet->freeze_panes(1, 0);凍結(jié)行
- while (my @row = $sth->fetchrow_array) {
- $sheet_col++;
- for (my $i=0;$i<=$cols_name ;$i++) {
- next if ($row[$i] eq '');
- $sheet->write_unicode($sheet_col,$i,$map->to_unicode($row[$i]));
- }
- }
- warn "all done!!!/n";
結(jié)束
- END {
- $report->close() if ($report);
- $dbh->disconnect();
- warn "write to: $ARGV[0]/n";
生成GB2312編碼系統(tǒng)
- my $map = Unicode::Map->new("gb2312");
產(chǎn)生報(bào)表
my $report = Spreadsheet::WriteExcel::Big->new("$ARGV[0]") || die "不能生成報(bào)表文件:$!";
創(chuàng)建報(bào)表的工作表
- my $sheet = $report->add_worksheet('data_report');
創(chuàng)建格式
- my $title_style = $report->add_format(); $title_style->set_size(11); $title_style->set_bold(); $title_style->set_align('center');
初始化數(shù)據(jù)指針
- my $sheet_col = 0;
創(chuàng)建表格
- for (my $i=0;$i<=$cols_name ;$i++) {
- $sheet->set_column($cols[$i], length($cols_name[$i])+4);
- $sheet->write_unicode($sheet_col,$i,$map->to_unicode($cols_name[$i]),$title_style);
- }
$sheet->freeze_panes(1, 0);凍結(jié)行
- while (my @row = $sth->fetchrow_array) {
- $sheet_col++;
- for (my $i=0;$i<=$cols_name ;$i++) {
- next if ($row[$i] eq '');
- $sheet->write_unicode($sheet_col,$i,$map->to_unicode($row[$i]));
- }
- }
- warn "all done!!!/n";
結(jié)束
- END {
- $report->close() if ($report);
- $dbh->disconnect();
- }
以上的相關(guān)內(nèi)容就是對(duì)從MySQL導(dǎo)出XLS數(shù)據(jù)庫工具的介紹,望你能有所收獲。
【編輯推薦】