my $sth = $dbh->prepare("SELECT a.name,b.name as capital, a.continent,a.region, a.lifeexpectancy,a.surfacearea,a.population FROM country a, city b WHERE a.capital=b.id ORDER BY 1"); $dbh->do("SET search_path to world") or die; $sth->execute(); my $row=1; while ($a = $sth->fetchrow_hashref()) { $worksheet->write($row,0, $a->{name}, $bold); $worksheet->write($row,1, $a->{capital}); $worksheet->write($row,2, $a->{continent}); $worksheet->write($row,3, $a->{region}); $worksheet->write($row,4, $a->{lifeexpectancy}); $worksheet->write($row,5, $a->{surfacearea}); $worksheet->write($row,6, $a->{population}); $row++; }