0

i need some help. I want to know what to do if i want to send an excel file generated by PHPexcel to the user downloading folder. The application works in a local network and it deals with billing.I need if a user click on the printing button defined in the application, the application should generate the invoice and downloading it to the downloading folder of his computer and if possible read automatically. Here the code i use but it doesn't work:

<?
php header('Pragma: public');
header('Expires: 0');
header('Content-Type: application/vnd.openxmlformats- officedocument.spreadsheetml.sheet');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream');
header('Content-Type: application/download');
header("Content-Disposition: attachment;filename=attendance.xlsx");
header('Content-Transfer-Encoding: binary');
……..    
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
?>

Thx in advance!

ʰᵈˑ
  • 11,279
  • 3
  • 26
  • 49
hmdw
  • 23
  • 1
  • 6
  • Point #1 - A response can only have a single content type; if you setthis several times via headers, only the last defined content type will actually be used – Mark Baker Oct 22 '14 at 15:48
  • Point #2 - There are several examples in the /Examples folder of PHPExcel that show the headers to use for downloading different formats, why aren't you using those? – Mark Baker Oct 22 '14 at 15:49
  • Point #3 - What do you mean by "doesn't work"? What does it do? Does it show any errors? Does it download a corrupted file? does it set the client's PC on fire? – Mark Baker Oct 22 '14 at 15:51
  • Thanks so much Mark Baker, i've already found a solution for that.By the way, I got another problem. I found too many problems in installing the application in a local network. I use wampserver as the local server(in my computer only) for my application. I want to use a windows server 2012 or 2003 to install the application in the network I created so that different users can access to it. Would you please give me even the link that explains the steps clearly and in details? – hmdw Oct 28 '14 at 15:28
  • There isn't much to installation: you copy the folders/files to your server, then point your code to it – Mark Baker Oct 28 '14 at 15:38
  • Why do you mean by pointing the code to it? – hmdw Oct 28 '14 at 15:42
  • I mean that you `include` the `PHPExcel.php` file, as shown in all the Examples – Mark Baker Oct 28 '14 at 15:43
  • Thx! Mark, I'm sorry to bother again. I got the same problem again. the excel downloaded file doesn't open. this time i have a file corrupted and non-compatible extension message. What is amazing is that, in the local computer it works perfectly with wampserver, but once in another server I got the this message. What do I have to do please? I'm under pressure to solve the problem, please. – hmdw Nov 03 '14 at 08:00
  • Open the file in a text editor. Look for any leading/trailing whitespace characters, any BOM header, or any PHP error messages embedded in plaintext in the body of the file – Mark Baker Nov 03 '14 at 08:06
  • Ok, I check and I tell you what – hmdw Nov 03 '14 at 08:23
  • I don't see anything wrong in the code. I think what is good is I post the code for you so that you can see by yourself. – hmdw Nov 03 '14 at 08:32
  • I'm not suggesting that you look in the code, I'm suggesting that you look in the Excel file – Mark Baker Nov 03 '14 at 09:20

0 Answers0