我需要使用PHPSspreadsheet从Wordpress网站导出Excel文件。
我已经安装了软件包,并且将他们的测试用例放入了一个函数中,但是它什么也没做。我在自定义插件文件中具有这些功能。当我将“ use PhpOffice”部分放到我的原始函数中时,它出现了一个错误,因此我知道它必须在函数之外,但是我仍然不确定它是否在正确的位置。
我将PHPSpreadsheet示例放到另一个函数中,因此它将在init上运行,但我只是在这里乱搞。...
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
//I added this function (spreadfunction) to try to have PHPSpreadsheet run at init for header reasons.
add_action('init', 'spreadfunction');
function spreadfunction() {
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'Hello World !');
$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');
}
//Originally, I had the sample code in this function, but no luck there, but I am using this to trigger it and so I can pass data to it ultimately.
function update_attendance_report_function() {
spreadfunction();
exit;
}
add_action( 'admin_post_nopriv_attendance_report', 'update_attendance_report_function' );
add_action( 'admin_post_attendance_report', 'update_attendance_report_function' );