doumor942473 2019-01-03 00:49
浏览 46

使用PHPSpreadsheet创建XLS文件,不在Wordpress的范围内工作

I need to use PHPSspreadsheet to export an excel file from a Wordpress site.

I have the package installed, and I put their test case into a function, but it isn't doing anything. I have these functions in a custom plugin file. When I put the "use PhpOffice" part into my original function it gve an error, so I understand it has to be outside of the function, but I am still not sure it is in the right spot.

I put the PHPSpreadsheet example into another function so it would run at init, but I am just hacking away here....

<?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' );
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭