PHPExcel 不提供来自 Mysql 的所有数据
PHPExcel don't give all data from Mysql
我使用 PHPExcel
将我的 table 数据导出到 excel 文件
在我的代码中,我尝试在一个 excel sheet 中从 2 table 导出我的代码,但是
问题是我有所有数据 - 1
我的意思是如果我有 5 行应该在 excel 文件中我只收到 4
这是我的代码:
<?php
$project=$_POST['project'];
//populate the data
$row=4;
while($data=mysqli_fetch_object($query)){
$excel->getActiveSheet()->setCellvalue('A'.$row,$data->db_projectid)
->setCellvalue('B'.$row,$data->db_projectname)
->setCellvalue('C'.$row,$data->loc)
//incriment the row
$row++;
}
//make table headers
$excel->getActiveSheet()
->setCellValue('A1','Project')
->setCellValue('A3','#')
->setCellValue('B3','Project Name')
->setCellValue('C3','Location');
if(mysqli_num_rows($activitieQuery)>0){
$row=7;
while($data=mysqli_fetch_object($activitieQuery)){
$excel->getActiveSheet()
->setCellvalue('A'.$row,$data->db_id)
->setCellvalue('B'.$row,$data->db_activityname)
->setCellvalue('C'.$row,$data->db_category)
->setCellvalue('D'.$row,$data->db_priority);
//incriment the row
$row++;
}
//make table headers
$excel->getActiveSheet()
->setCellValue('A6','Activities')
->setCellValue('A7','#')
->setCellValue('B7','Activity Name')
->setCellValue('C7','Category')
->setCellValue('D7','Priority');
}
//write the result to a file
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="project.xlsx"');
header('Cache-Control:max-age=0');
header('Cache-Control: max-age=1');
$file=PHPExcel_IOFactory::createWriter($excel,'Excel2007');
//output to php output instead of filename
$file->save("php://output");
exit;
?>
我怎样才能毫无问题地收到我想要的所有数据。
当我打印 mysqli_num_rows($activitieQuery);
我有数字 5
如果我打印 $data->db_id
我收到 5 个 id 而不是 4
但是当我导出到 excel 文件时,我收到 4 个 id 而不是 5 我该如何解决这个问题?
对于我的第一个 table 我没有任何问题我的问题是第二个 table tbl_activities 只有任何人知道如何解决这个问题?
第二个查询从 $row = 7;
开始,然后将其替换为 header
->setCellValue('A7', '#')
->setCellValue('B7', 'Activity Name')
->setCellValue('C7', 'Category')
->setCellValue('D7', 'Priority')
->setCellValue('E7', 'Supplier')
...
所以用 $row = 8;
替换 $row = 7;
应该会有帮助
我使用 PHPExcel
将我的 table 数据导出到 excel 文件
在我的代码中,我尝试在一个 excel sheet 中从 2 table 导出我的代码,但是
问题是我有所有数据 - 1
我的意思是如果我有 5 行应该在 excel 文件中我只收到 4
这是我的代码:
<?php
$project=$_POST['project'];
//populate the data
$row=4;
while($data=mysqli_fetch_object($query)){
$excel->getActiveSheet()->setCellvalue('A'.$row,$data->db_projectid)
->setCellvalue('B'.$row,$data->db_projectname)
->setCellvalue('C'.$row,$data->loc)
//incriment the row
$row++;
}
//make table headers
$excel->getActiveSheet()
->setCellValue('A1','Project')
->setCellValue('A3','#')
->setCellValue('B3','Project Name')
->setCellValue('C3','Location');
if(mysqli_num_rows($activitieQuery)>0){
$row=7;
while($data=mysqli_fetch_object($activitieQuery)){
$excel->getActiveSheet()
->setCellvalue('A'.$row,$data->db_id)
->setCellvalue('B'.$row,$data->db_activityname)
->setCellvalue('C'.$row,$data->db_category)
->setCellvalue('D'.$row,$data->db_priority);
//incriment the row
$row++;
}
//make table headers
$excel->getActiveSheet()
->setCellValue('A6','Activities')
->setCellValue('A7','#')
->setCellValue('B7','Activity Name')
->setCellValue('C7','Category')
->setCellValue('D7','Priority');
}
//write the result to a file
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment; filename="project.xlsx"');
header('Cache-Control:max-age=0');
header('Cache-Control: max-age=1');
$file=PHPExcel_IOFactory::createWriter($excel,'Excel2007');
//output to php output instead of filename
$file->save("php://output");
exit;
?>
我怎样才能毫无问题地收到我想要的所有数据。
当我打印 mysqli_num_rows($activitieQuery);
我有数字 5
如果我打印 $data->db_id
我收到 5 个 id 而不是 4
但是当我导出到 excel 文件时,我收到 4 个 id 而不是 5 我该如何解决这个问题?
对于我的第一个 table 我没有任何问题我的问题是第二个 table tbl_activities 只有任何人知道如何解决这个问题?
第二个查询从 $row = 7;
开始,然后将其替换为 header
->setCellValue('A7', '#')
->setCellValue('B7', 'Activity Name')
->setCellValue('C7', 'Category')
->setCellValue('D7', 'Priority')
->setCellValue('E7', 'Supplier')
...
所以用 $row = 8;
替换 $row = 7;
应该会有帮助