开发者

SQl 2 XLS with PHP

Is there a goo开发者_开发问答d PHP Class to export data from mysql to XLS file?


It's very easy to do this using the PHPExcel library. It won't read the database for you; but you can easily write a script that reads the database, then build up a worksheet as you loop through the rows.

EDIT

Read the documentation, look at the example code:

require_once './Classes/PHPExcel.php';

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC";

if ($result = $mysqli->query($query)) {
    // Create a new PHPExcel object
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getActiveSheet()->setTitle('List of Cities');

    // Loop through the result set
    $rowNumber = 1;
    while ($row = $result->fetch_row()) {
        $objPHPExcel->getActiveSheet()->fromArray($row,NULL,'A'.$rowNumber++);
    }
    // Save as an Excel BIFF (xls) file
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('CityList.xls');
}


phpMyAdmin is a PHP based mySQL interface that supports exporting to Excel. It's an application and not a standalone class, though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜