我在使用XLS函数将查询结果添加到xls文件中时遇到了一些困难。 我有一个html和一个php文件正在做这个工作。 查询正常工作,但我认为XLS函数不提取查询结果。按下html文件中的按钮后,我得到“whitescreen”。
<div class="right" style="width:940px;">
<a href="/statistics/orders/stats.xls" i18n:translate="">Download as .XLS</a>
</div>
我希望将查询保存在可以保存的xls文件中。 php看起来像这样:
<?PHP
import( 'pages.admin' );
class AdminPortalStatistics extends AdminPage implements IView {
protected $template = 'order.stats';
public
function Execute() {
$kode = 'ST1';
$from = '2017-06-20';
$to = '2017-07-29';
if ($_GET['from'] && $_GET['to']) {
$from = $_GET['from'];
$to = $_GET['to'];
$query = "SELECT * from history_ordrer ho INNER JOIN history_cusomer hc ON ho.ordrenr = hc.ordrenr INNER JOIN history_mal hm ON ho.ordrenr = hm.ordrenr INNER JOIN histort_orderline hol ON ho.ordrenr = hol.ordrenr INNER JOIN kunde k ON ho.uid = k.uid WHERE ho.kode = ? AND ho.time BETWEEN ? AND ? AND ho.deleted is null order by ho.ordernr desc";
$orders = DB::query($query, $kode, $from, $to) - > fetchAll(DB::FETCH_ASSOC);
$this - > stats = $orders;
}
$this - > kode = $kode;
$this - > from = $from;
$this - > to = $to;
}
public function XLS( ) {
$this->Execute( );
$this->setTemplate( false );
$oldreporting = error_reporting( 0 );
require_once 'Spreadsheet/Excel/Writer.php';
// Creating a workbook
$workbook = new Spreadsheet_Excel_Writer();
// sending HTTP headers
$workbook->send('test.xls');
// Creating a worksheet
$worksheet =& $workbook->addWorksheet( 'Report' );
// write the data
$fields = array_merge( array( 'Period' ), $this->series );
$worksheet->writeRow( $row++, 0, $fields );
foreach( $this->values as $graph ) {
$line = array_merge( array( $graph['label'] ), $graph['data'] );
$worksheet->writeRow( $row++, 0, $line );
}
// Let's send the file
$workbook->close();
error_reporting( $oldreporting );
}
}
?>