我有这个PHPExcel代码:
/** Error reporting */
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
/** Include PHPExcel */
require_once '../Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
//$objPHPExcel->setActiveSheetIndex(0)
// ->setCellValue('A1', 'Hello')
// ->setCellValue('A2', 'world!')
$row = 2;
while($row_data = mysql_fetch_assoc($result)) {
$col = 1;
foreach($row_data as $key=>$value) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $value);
$col++;
}
$row++;
}
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Results');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Output.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
基本上我是在动态查询数据库并将其放入一个 excel 文件中。
我只想在一些标题中硬编码。所以对于 A1,我想在“Hello”和 A2 中硬编码:“World!” 查询数据库并将数据从 B 列开始