fix encoding of characters in generated sheet
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 24 Mar 2008 15:57:14 +0000 (15:57 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 24 Mar 2008 15:57:14 +0000 (15:57 +0000)
git-svn-id: svn://svn.rot13.org/SQL2XLS@2 2e857b76-582b-47e5-ad5c-b3ba0f0ee29b

sql2xls.cgi

index 1627e09..908e9cd 100755 (executable)
@@ -10,6 +10,12 @@ use Spreadsheet::WriteExcel;
 use DBI;
 use CGI::Carp qw(fatalsToBrowser);
 use CGI qw(path_translated);
+use Encode qw/decode/;
+
+# Connect to DB
+my $connect = "DBI:Pg:dbname=new";
+my $user = "web";
+my $passwd = "";
 
 my $debug = 1;
 
@@ -30,13 +36,12 @@ if ($0 =~ m/\.cgi$/i) {
        $workbook = Spreadsheet::WriteExcel->new("sql_result.xls");
 }
 
-# Connect to DB
-my $connect = "DBI:Pg:dbname=new";
-my $user = "web";
-my $passwd = "";
-
 my $dbh = DBI->connect($connect,$user,$passwd) || die $DBI::errstr;
 
+sub _c {
+       return decode('iso-8859-2', shift);
+}
+
 foreach my $sql_file (@sql_files) {
 
        my $sheet_name = $sql_file;
@@ -72,7 +77,7 @@ foreach my $sql_file (@sql_files) {
                my $fmt_comment = $workbook->addformat();    # Add a format
                $fmt_comment->set_bold();
 
-               $worksheet->write($row, 0, $comment, $fmt_comment);
+               $worksheet->write($row, 0, _c($comment), $fmt_comment);
                $row+=2;
        }
 
@@ -89,7 +94,7 @@ foreach my $sql_file (@sql_files) {
 
        while (my @row = $sth->fetchrow_array() ) {
                for(my $col=0; $col<=$#row; $col++) {
-                       $worksheet->write($row, $col, $row[$col] );
+                       $worksheet->write($row, $col, _c( $row[$col] ) );
                }
                $row++;
        }