将数据导出到由XLSXWriter创build的Excel文件(第2部分)

在Excel上继续无法打开由XLSXWriter创build的文件

用户表
在这里输入图像说明

test.php的

<?php if(isset($_POST['submit2']) && ($_POST['submit2'] == 'Export')) { //db connection $name = $_POST['name']; $record = FindName($name); if(count($record) > 0) { [?] } } else { ?> <form action="c.php" method="post"> Name: <input type="text" name="name" /> <input type="submit" name="submit2" value="Export" /> </form> <?php } function FindName($name) { $query = "SELECT * FROM user WHERE Name like '".$name."%'"; $result = mysqli_query($dbc, $query); $record = array(); while($row = mysqli_fetch_array($result)) { $record[] = $row; } return $record; } ?> 

的download.php

 <?php include('./PHP_XLSXWriter-master/xlsxwriter.class.php'); ini_set('display_errors', 0); ini_set('log_errors', 1); error_reporting(E_ALL & ~E_NOTICE); $filename = "example.xlsx"; header('Content-disposition: attachment; filename="'.XLSXWriter::sanitize_filename($filename).'"'); header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate'); header('Pragma: public'); $header = array( 'ID'=>'string', 'Name'=>'string', 'Age'=>'string', 'Gender'=>'string', ); for($i = 0; $i < count($record); $i++) { $data[$i] = array($record[$i]['ID'],$record[$i]['Name'],$record[$i]['Age'],$record[$i]['Gender']); } $writer = new XLSXWriter(); $writer->writeSheet($data,'Sheet1',$header); $writer->writeToStdOut(); ?> 

比方说,我在文本框中键入黄,然后单击导出button。
点击导出button后,find包含Wong word的名称,并将数据导出到excel。

我的问题是如何将$ recordvariables传递给download.php以便将数据导出到[?]的excel文件中? 有人能帮我吗?

而不是你的[?]require文件。

 if(count($record) > 0) { require "PATH_TO/download.php"; exit; // <- IMPORTANT to add exit // to not have in download response html data from test.php } 

因为variables$record已被定义( $record = FindName($name); )该variables可以在download.php