1
2
3
4
5
6
7
8
9
10
...
$sql = 'SELECT usagedate, title FROM songusage_query';
$sth = $dbh->prepare($sql);
$sth->execute();
#print Dumper $sth->fetchall_arrayref();
my $worksheet_2 = $workbook->add_worksheet($worksheetname[1]);
$worksheet_2->write_col(0, 0, $sth->fetchall_arrayref());
...
1
2
3
4
use Spreadsheet::WriteExcel;
my $excel = "/home/xxx/excel.xls";
my $workbook = Spreadsheet::WriteExcel->new($excel);
perldoc Spreadsheet::WriteExcelYou don't have to worry about binmode() if you are using filenames instead of filehandles. Spreadsheet::WriteExcel performs the binmode() internally when it converts the filename to a filehandle. For more information about binmode() see perlfunc and perlopentut in the main Perl documentation.
perldoc DBD::SQLiteDRIVER PRIVATE ATTRIBUTES ^
Database Handle Attributes
...
unicode
If set to a true value, DBD::SQLite will turn the UTF-8 flag on for all text strings coming out of the database. For more details on the UTF-8 flag see perlunicode. The default is for the UTF-8 flag to be turned off.
Also note that due to some bizareness in SQLite's type system (see http://www.sqlite.org/datatype3.html), if you want to retain blob-style behavior for some columns under $dbh->{unicode} = 1 (say, to store images in the database), you have to state so explicitely using the 3-argument form of "bind_param" in DBI when doing updates:
Code: (dl )1
2
3
4
5
6use DBI qw(:sql_types);
$dbh->{unicode} = 1;
my $sth = $dbh->prepare
("INSERT INTO mytable (blobcolumn) VALUES (?)");
$sth->bind_param(1, $binary_data, SQL_BLOB); # binary_data will
# be stored as-is.
Defining the column type as BLOB in the DDL is not sufficient.
1
2
3
4
$ sqlite3 utf8.db 'SELECT * FROM obst' | xxd
0000000: c384 7066 656c 7c6c 6563 6b65 720a c384 ..pfel|lecker...
0000010: 7066 656c 7c6c 6563 6b65 720a c384 7066 pfel|lecker...pf
0000020: 656c 7c6c 6563 6b65 720a el|lecker.