Ниже код:
$link = mysqli_connect('localhost', 'root', '', 'eshop');
$query1 = mysqli_query($link, "SELECT * FROM goods");
$myrow = mysqli_fetch_array($query1);
require_once './PHPExcel/Classes/PHPExcel.php';
$phpexcel = new PHPExcel();
$page = $phpexcel->setActiveSheetIndex(0);
$page->setCellValue("A1", "id");
$page->setCellValue("B1", "name");
$page->setCellValue("C1", "cost");
$page->setCellValue("D1", "description");
$page->setCellValue("E1", "ord");
$page->setCellValue("F1", "img");
$s = 2;
while($row = mysqli_fetch_array($query1))
{
$s++;
$page->setCellValue("A$s", $row['id']);
$page->setCellValue("B$s", $row['name']);
$page->setCellValue("C$s", $row['cost']);
$page->setCellValue("D$s", $row['description']);
$page->setCellValue("E$s", $row['ord']);
$page->setCellValue("F$s", $row['img']);
}
$page->setTitle("Example");
$objWriter = PHPExcel_IOFactory::createWriter($phpexcel, 'Excel2007');
$objWriter->save("example.xlsx");
база на локал хост:
что на выходе в экселе: