Using PHPSpreadsheet to create XLS files, Not Working within confines of Wordpress












0















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 PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;


//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' );









share|improve this question























  • Set your Wordpress to use debug-mode. You will have errors, probably because you are not including the files that provide the Spreadsheet and Xlsx classes (unless you've configured an auto-loader)

    – Phil
    Jan 3 at 1:23











  • I’m calling the auto loader elsewhere.

    – CRAIG
    Jan 3 at 1:24











  • codex.wordpress.org/Debugging_in_WordPress

    – Phil
    Jan 3 at 1:25











  • Is there a way to see if PHPspreadsheet is working right?

    – CRAIG
    Jan 3 at 1:56











  • Yes, enable debug mode, check for errors and fix them if there are any

    – Phil
    Jan 3 at 1:57
















0















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 PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;


//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' );









share|improve this question























  • Set your Wordpress to use debug-mode. You will have errors, probably because you are not including the files that provide the Spreadsheet and Xlsx classes (unless you've configured an auto-loader)

    – Phil
    Jan 3 at 1:23











  • I’m calling the auto loader elsewhere.

    – CRAIG
    Jan 3 at 1:24











  • codex.wordpress.org/Debugging_in_WordPress

    – Phil
    Jan 3 at 1:25











  • Is there a way to see if PHPspreadsheet is working right?

    – CRAIG
    Jan 3 at 1:56











  • Yes, enable debug mode, check for errors and fix them if there are any

    – Phil
    Jan 3 at 1:57














0












0








0








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 PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;


//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' );









share|improve this question














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 PhpOfficePhpSpreadsheetSpreadsheet;
use PhpOfficePhpSpreadsheetWriterXlsx;


//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' );






php wordpress phpspreadsheet






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 0:49









CRAIGCRAIG

4241617




4241617













  • Set your Wordpress to use debug-mode. You will have errors, probably because you are not including the files that provide the Spreadsheet and Xlsx classes (unless you've configured an auto-loader)

    – Phil
    Jan 3 at 1:23











  • I’m calling the auto loader elsewhere.

    – CRAIG
    Jan 3 at 1:24











  • codex.wordpress.org/Debugging_in_WordPress

    – Phil
    Jan 3 at 1:25











  • Is there a way to see if PHPspreadsheet is working right?

    – CRAIG
    Jan 3 at 1:56











  • Yes, enable debug mode, check for errors and fix them if there are any

    – Phil
    Jan 3 at 1:57



















  • Set your Wordpress to use debug-mode. You will have errors, probably because you are not including the files that provide the Spreadsheet and Xlsx classes (unless you've configured an auto-loader)

    – Phil
    Jan 3 at 1:23











  • I’m calling the auto loader elsewhere.

    – CRAIG
    Jan 3 at 1:24











  • codex.wordpress.org/Debugging_in_WordPress

    – Phil
    Jan 3 at 1:25











  • Is there a way to see if PHPspreadsheet is working right?

    – CRAIG
    Jan 3 at 1:56











  • Yes, enable debug mode, check for errors and fix them if there are any

    – Phil
    Jan 3 at 1:57

















Set your Wordpress to use debug-mode. You will have errors, probably because you are not including the files that provide the Spreadsheet and Xlsx classes (unless you've configured an auto-loader)

– Phil
Jan 3 at 1:23





Set your Wordpress to use debug-mode. You will have errors, probably because you are not including the files that provide the Spreadsheet and Xlsx classes (unless you've configured an auto-loader)

– Phil
Jan 3 at 1:23













I’m calling the auto loader elsewhere.

– CRAIG
Jan 3 at 1:24





I’m calling the auto loader elsewhere.

– CRAIG
Jan 3 at 1:24













codex.wordpress.org/Debugging_in_WordPress

– Phil
Jan 3 at 1:25





codex.wordpress.org/Debugging_in_WordPress

– Phil
Jan 3 at 1:25













Is there a way to see if PHPspreadsheet is working right?

– CRAIG
Jan 3 at 1:56





Is there a way to see if PHPspreadsheet is working right?

– CRAIG
Jan 3 at 1:56













Yes, enable debug mode, check for errors and fix them if there are any

– Phil
Jan 3 at 1:57





Yes, enable debug mode, check for errors and fix them if there are any

– Phil
Jan 3 at 1:57












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015036%2fusing-phpspreadsheet-to-create-xls-files-not-working-within-confines-of-wordpre%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015036%2fusing-phpspreadsheet-to-create-xls-files-not-working-within-confines-of-wordpre%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]