$::dbs = DBI->connect("dbi:Pg:dbname=test","test","test",{PrintError => 0});
if ($DBI::err != 0)
{ print $DBI::errstr . "\\n";
exit($DBI::err);
}
my $workbook = Spreadsheet::WriteExcel->new("/home/test/REPORT".$curr.".xls");
$worksheet = $workbook->addworksheet();
$format = $workbook->addformat();
$format->set_bold();
$format->set_align(\'center\');
$worksheet->set_column(0, 0, 30);
$worksheet->set_column(0, 1, 30);
$worksheet->set_column(0, 2, 30);
$worksheet->write(0, 0, decode(\'cp1251\', \'Поле1\'), $format);
$worksheet->write(0, 1, decode(\'cp1251\', \'Поле2\'), $format);
$worksheet->write(0, 2, decode(\'cp1251\', \'Поле3\'), $format);
$query = "Select distinct code_product from report where time_create>".$time1." and time_create<".$time2."";
$sth = $dbs->prepare($query);
$rv = $sth->execute();
my $fo=1;
while ($ref = $sth->fetchrow_hashref())
{
($tablename) = ($ref->{\'code_product\'});
$querys = "Select count(*) from report where code_product=".$tablename." and time_create>".$time1." and time_create<".$time2."";
$sths = $dbs->prepare($querys);
$rv = $sths->execute();
@refs = $sths->fetchrow_array();
$worksheet->write($fo, 0, "$tablename");
$worksheet->write($fo, 1, $refs[0]);
$fo++;
}
$sths->finish();
$::dbs->disconnect();
$ftp = Net::FTP->new("192.168.0.1",Timeout => 30, Debug => 1, Passive =>1) || die "Can\'t connect to ftp server.\\n";
$ftp->login(\'test\',\'test\') || "error.\\n";
$ftp->cwd("out");
$ftp->cwd("code");
#set the mode to ascii
#$ftp->ascii();
#закачка на фтп
$ftp->binary();
$ftp->put(\'/home/test/REPORT\'.$curr.\'.xls\') or die "get failed ", $ftp->message;
#отключение от фтп
$ftp->quit();