Export XLS Database Tools from MySQL (cross-platform)

Source: Internet
Author: User
This script is a tool for generating Excel xls files using Perl. Depending on some module, you can use it under Linux to produce XLS files. Use the command-line arguments. It's very handy. This script is a tool for generating Excel xls files using Perl. Depending on some module, you can use it under Linux to produce XLS files. Use the command-line arguments. Very convenient.
#!/usr/bin/perl
#===============================
# MySQL to Excel
# lastmodify at 2005-1-5
# Copyright by Hoowa
#=============================
Use strict; #严格语法检测
Use DBI; #数据库引擎
Use Unicode::map; #Unicode引擎
#use Spreadsheet::WriteExcel; #Excel报表引擎
Use Spreadsheet::writeexcel::big; #大文件Excel报表引擎
My $hostname = ' 192.168.1.133 ';
My $username = ' user ';
My $password = ' pass ';
My $dbname = ' db ';
My $trans _compress=1; #任何非一的数关闭数据库到程序间传输压缩
$|=1;
My @cols = (' a:a ', ' b:b ', ' c:c ', ' d:d ', ' e:e ', ' f:f ', ' g:g ', ' h:h ', ' i:i ', ' j:j ',
' K:k ', ' l:l ', ' m:m ', ' n:n ', ' o:o ', ' p:p ', ' q:q ', ' r:r ', ' s:s ', ' t:t ', ' u:u ',
' V:v ', ' w:w ', ' x:x ', ' y:y ', ' z:z ', ' aa:a ', ' bb:b ', ' cc:c ', ' dd:d ', ' ee:e ',
' Ff:f ', ' gg:g ', ' hh:h ', ' ii:i ', ' jj:j ', ' kk:k ', ' ll:l ', ' mm:m ', ' nn:n ',
' Oo:o ', ' pp:p ', ' qq:q ', ' rr:r ', ' ss:s ', ' tt:t ', ' uu:u ', ' vv:v ', ' ww:w ',
' Xx:x ', ' yy:y ', ' zz:z ');
#解析来内容
if ($ #ARGV!= ' 1 ') {
Print qq~syntax:my2excel.pl <writefilename> "[Where expression]"
~;
Exit
}
$ARGV [1]=~ s/"//g;
Warn qq~
MySQL to Excel
by Hoowa.sun
=====================
sql: $ARGV [1]
~;
My $DBH =
Dbi->connect ("dbi:mysql:mysql_compression= $trans _compress;
database= $dbname; host= $hostname ", $username, $password);
My $sth = $dbh->prepare ("$ARGV [1]") | | Die $DBH->errstr;
My $rows = $sth->execute () or Die $sth->errstr;
Warn "Rows: $rows found.";
My @cols_name = @{$sth->{' name '}};
if ($ #cols_name > $ #cols) {
print "Table $ARGV [1] fields out of allow!! (Max Num. >.) ($ #cols 1). ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.