Welcome Guest, Not a member yet? Register   Sign In
PHPExcel doesn't work
#1

[eluser]hrg.vincent[/eluser]
My problem here is there is not pop up to ask where to save, and when I clicked on save button, the data all appear in web with some funny wording. Please help.

Code:
public function getSaveReport()
{
$this->load->library('PHPExcel');

$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("title")
         ->setDescription("description");

// Assign cell values
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'VX No.');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Pax Name');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Company Name');
$objPHPExcel->getActiveSheet()->setCellValue('D1', 'Embassy');
$objPHPExcel->getActiveSheet()->setCellValue('E1', 'Visa Processing Type');
$objPHPExcel->getActiveSheet()->setCellValue('F1', 'Status');
$objPHPExcel->getActiveSheet()->setCellValue('G1', 'Created by');
$objPHPExcel->getActiveSheet()->setCellValue('H1', 'Created On');

// Save it as an excel 2003 file
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="vincent_test.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
#2

[eluser]numberduck[/eluser]
Those headers look OK, were there any warnings?
My guess is that you already had some output sent to the browser before the headers were set. You must not write any output, even white space, before setting the headers.
#3

[eluser]hrg.vincent[/eluser]
[quote author="numberduck" date="1384943687"]Those headers look OK, were there any warnings?
My guess is that you already had some output sent to the browser before the headers were set. You must not write any output, even white space, before setting the headers.[/quote]

no any warnings at all, just display a blank page.
if i change to the code below, it show also blank page, but at least it save to root folder.
But now my problem is, I need it to pop out and ask where to save.
Code:
// change the code to
$objWriter->save("test.xls");

// instead of
$objWriter->save('php://output');

So, anyone can help?
#4

[eluser]hrg.vincent[/eluser]
anyone can help? currently I can save into server only but I want to save it into my computer instead of server.
#5

[eluser]numberduck[/eluser]
[quote author="hrg.vincent" date="1385024261"]anyone can help? currently I can save into server only but I want to save it into my computer instead of server.[/quote]
Perhaps you are missing fopen wrappers?

See if this works instead?
Code:
$objWriter->save("test.xls");
header("Content-Type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=test.xls");
echo file_get_contents("test.xls");
#6

[eluser]hrg.vincent[/eluser]
doesn't work also..
once click no action.
#7

[eluser]CroNiX[/eluser]
Try using CI's download helper.
#8

[eluser]CroNiX[/eluser]
Also, a blank page usually indicates that errors are being triggered but you don't have php set up to display them via the browser, so it outputs a blank page instead of the error messages. You might look at php's error log to see if they are being logged there.

You can also try placing
Code:
ini_set('display_errors', 1);
at the top of your index.php and see if it will help show you the errors.
#9

[eluser]hrg.vincent[/eluser]
I follow CI’s download helper but doesn't popup window also.
Code:
$this->load->helper('download');
$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);

From my code in first post if I replace the code, it work but just that I do not want to download into my own server, and I want it like popup a window for save into own desktop.
Code:
// From code
$objPHPExcel->save('php://output');

// replace to code
$objWriter->save(test.xls');

I've placed to check error.. but no error at all.
Code:
ini_set('display_errors', 1);
#10

[eluser]hrg.vincent[/eluser]
anyone can help?




Theme © iAndrew 2016 - Forum software by © MyBB