I'm having some issues regarding this php library which is not working as i want to, i hope you can help me out with this one.
My program first calls a service through ajax which returns a .json.Then with the given.json i need to save it in a xls excel file, for this I'm using another ajax which calls to php service to save it locally (generarExcel2.php)
Below is the js/ajax part of the code in my html which actually works fine.
$(document).ready(function () {
var exceljsondatos;
var path ="{{urlSf}}";
$.ajax({
type: "POST",
url: path,
dataType: 'json',
success: function (data) {
exceljsondatos = data;
$('#genExcel').click(function () {
$.ajax({
type: "POST",
url: "generarExcel2.php",
data: exceljsondatos,
success: function (resultado) {
$('#resp').html(" Function call successful"); }
});//End exel ajax call
});//End click event
}//End of success
});//End ajax data call
}); //End of document ready
This shows on my html the correct message, so seems to work in this side. On my php i've checked its recieving the $_POST content correctly through var_dump but here comes the main problem.
I cant manage to prompt the user to save the data. I've tried using writer and with IOFactory, none works Here is the php code so you can take a look.
<?php
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\IOFactory;//Option1
//use PhpOffice\PhpSpreadsheet\Writer\Xls;//Option2
$filename="Excel_jano_test";
$spreadsheet = new Spreadsheet();
$excel_writer = IOFactory::createWriter($spreadsheet, 'Xls');//Option1
//$excel_writer = new Xls($spreadsheet); //Option2
$activeSheet = $spreadsheet->getActiveSheet();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'. $filename .'.xls"');
header('Cache-Control: max-age=0');
$activeSheet->setCellValue('A1' , 'NUM.SOLICITUD');//example for dummy
$excel_writer->save('php://output');//THIS SHOULD PROMPT USER
I've tried changing last line to $excel_writer->save('otherfile.xls'); and it saves changes CORRECTLY on server. If you can see what i cant i will be grateful. Thanks a lot!
One more thing. I've checked that if i click on the route such as actually works and PROMPTS user but this way it wont be passing or recieving data.