wrong output

Topics: Developer Forum
Feb 29, 2012 at 1:15 PM

Hi,

        I dont want to save the excel file.Instead it should open directly.

[code]

<?php
require_once '../classes/PHPExcel.php';

/** Error reporting */
error_reporting(E_ALL);
set_time_limit(0);
// Create new PHPExcel object
//echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();
// Create a first sheet
//echo date('H:i:s') . " Add data\n";
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', "Firstname");
$objPHPExcel->getActiveSheet()->setCellValue('B1', "Lastname");
$objPHPExcel->getActiveSheet()->setCellValue('C1', "Phone");
$objPHPExcel->getActiveSheet()->setCellValue('D1', "Fax");
$objPHPExcel->getActiveSheet()->setCellValue('E1', "Is Client ?");

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);

// Save Excel 2007 file
//echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$objWriter->save('php://output');
exit;
?>

[/code]

 

//output

PK`”]@G’D²Xð[Content_Types].xml­”MNÃ0…÷œ"ò%nY „švAa •(0ö¤±êØ–gúw{&i ‰@ÕnbEö{ßøyìÑdÛ¸l m𥑁×ÁX¿(ÅÛü)¿’òF¹à¡;@1_æ»˜±Øc)j¢x/%ê…Eˆày¦ ©QÄ¿i!£ÒKµy3ÜJ<§œZ1½0?YÙL%zV cäÖIb7؇û‰ìa/lÙ¥P1:«qáríÍjªÊj0A¯–Íuë""íàÙ(Œ ”Á€WìMä)Tjå({ܲû>óOãÂ,XÙ­ÁÚÆ>Bÿ†~×­Ï ‚õÓ¤6ÜJ=¡oBZ¾‡°¼tìíX4Êú¾Cgñ,…ˆ’QgmrLÙÙ¯cïeëàtø± Zõ?‰‡´»hPvÃð±úÿuÕj•À¼Râæ¸øûî}¬CvÖøPK`”]@¶78éK _rels/.rels­’ÍjÃ0 €ï{ £{£´…1F^Ê ·2²Ðlå‡$–±½-}ûy‡±ºÒÃŽ–¥OŸ„vûyÕ;‡Ø‹Ó°.JPìŒØÞµ^ê§Õ¨˜ÈYű†3GØWw»g)åšØõ>ª qQC—’DŒ¦ã‰b!ž]þi$L”ò3´èÉ Ô2nÊòÃoT ¦:Z áh· ê³ç[ØÒ4½áƒ˜·‰]ºÐyNì,Û•¹>¤>£j -' VÌ)‡#’÷EF^6ÚÜnô÷´8q"K‰ÐHàë>_ׄÖÿ¹¢eƏÍ<⇄áUdøvÁÅ TŸPK`”]@„$±Vé¹xl/_rels/workbook.xml.rels­’ÁjÃ0Dïý ±÷ZvZJ)‘s)\[÷„´¶LlIh7mý÷UH¡ŸÄ¬Ø™ÇHëÍ÷8ˆOLÔ¯ *JèM°½ï|4ÛûgÄÚ[= &$ØÔwë74çr}$‘M<)pÌñEJ2GMEˆèóMÒ¨9ËÔɨÍ^w(Weù$ÓÜê O±³ ÒÎV š)â¼CÛö_ƒ9ŒèùJ„$ž†Ì/:dG]d×ãWKÆsÞÅsúŸ<«[ ‹VàtBûÎ)?ð¼‰ùøÌã’0_!íÉ!òä4úEÍÇ©yñãêPK`”]@×Íê†;docProps/app.xmlSÁnÛ0 ½ï+ Ý9Á0¬bH7ôÐb’¶gN¦c¡¶$ˆ¬‘ìë';°ë´=Õ§ÇLJ§'ŠV7ǶÉ:Œd½+Är‘‹ ñ¥u‡B<î_]‹Œ\ wXˆ’¸ÑßÔ6ú€‘-R–¢fk)ÉÔØ-RÛ¥Nåc œÊx¾ª¬Á[o^[t,WyþCâ‘Ñ•X^…ÉPœ×Õ´ô¦ÏGOûSH~Zý ¡±8]R?X=ùŠ³_Gƒ’ó¦JF;4¯ÑòIçJÎKµ3Ðà&ë B%ßu‡ÐÏl 6’V¯;4ìcFö_šÚJd°Sˆ¢Çâ,;nqÔÏ>¾PÈ¤äDp®cû]/A—B9Iø2âÞrƒô§ÚBäO/片 Ⳍ"Ž‡½³ßø6€;͆¿ñ1ø8L]ɱ­ÀÁ{ƒ Ý[÷Baïoqœü%©v5D,ÓcM/3ê.]!6½~Sƒ;`9j>6ú=y:ÿ z¹ZäéÖcä”|[{ýPK`”]@÷yà£rdocProps/core.xml¥’ÁNÃ0Dï|Eä+Jí¤A” '*!µ®Æ^ZÓĶì-iþÇiS Ü8E“?ïŽ\Þìš:ùç•Ñ3’MI@ #•^ÍÈóò!½"‰G®%¯†éÀ“›ê¬¶ÆÁ“3*ðIi_;#kD[PêÅî'!¡ƒùn\Ã1H·¢–‹ _Í»¤ —9큩‰d”bDÚ­«#@ 54 ÑÓl’ÑcÁ5þÏÑù–lvþŒÌ1½ój ¶m;i§1æÏèëüqWM•î«@ªRŠB8àh\õ¬7Ú´:¹tI¿y}5÷8¿+·ÝïøïH¹_sÀ€LÂxÅ°ÌÁy™ÞÝ/H•³,OYžæ×Ë쪘^Œ³‹bÊú1N Gj³¿éØ%v k«Å¯L6Ü)ýcƒÝ%xá”Åð«hüÚoß>@à`Ž"t´®5Nú*6vTýK û­Œëë‡:yÅÕPK`”]@­­áJxl/theme/theme1.xmlíY[sÚ8~ß_¡ñ{k 6%™’L Ðî¶i3 íN¶°UdË#‰¤üû=¾€­X´¤Mgw§å,ù;÷‹ÌËó/)'wT*&²±ã=ï9„f¡ˆX‹ù³‘C”†,.2:v¶T9çg¼„SÐ”$ÏÔ)ŒDëüÔuUˆÛ ž‹œfxo%d —2v# ÷È6ån¿×º)°Ì!¤ÈõýjÅBJKçlÇ|Æñ+Ӫع¼ K‰mŠ­½âGmÕ”Kr|ì œHÜ/èíJ㍱Ó+?Ž{öÒÝq}€¶E7/?5]M­û%Œ—{Bo¸ÜóïWü»¸Ùl6y{~%Â-õ:X>ò&;ž-PuÙå=í=ßÄ·ø:ø“ÉdœøAƒ÷;øQoè_ô ¼ßàƒ®þ“‹éthàƒ?ìàç/N†¾‰/A gÙºƒ.⹏̲üµ>Bøh— ÊmeWEŸéC¹–Âg!ç(ƒ šeDosº‚qSH—’A!N)´îT[¡êl²ˆ %ËõØù+¬ˆr~N΋ú²¸µã”‰³ƒ´ ²Â.$,Û°K©"ïè=¹)jnaL—òq‹˜A "-À™N à»-pnBMG}”XÞ6à«ÍgC×ÛDn4³ß$©¼‚O„´šó¦Õ6g“ÅvárÓÆÝÜÙdO„s¶É1O™å4¡†š×£ 1ͨ&Å=±¦ÔBö‰1ïW,”B‰•&Ÿ™³ºdÁ–ÚNôš¥—-ØCmøæê#™ncIïL$&?pKÊ 7¾‚†Ôª1¤¼| :±)y»•¡áp¥1Ò1å‚Ì"ª”æ½Üê¾ì3Ö°_ñmj"¥fkò-ÑF^Šõ44·ê̲¤ýS­1E\ mUB˜R¬1 ÷GFõãÊú‹{‚w6²îÉFwMYöµVËöÚ_¥Õ^àc…Ñ`áþ‡mõ6Ù5ÅLþÝUwÕ_±«ªåc{iÓ>ÝöL[òK¸+Æù­ÞrúV•W¡ÒÑ7ËEI´Ÿ§ó/kq.–P^)ôßL'· ä(Æ+%Īf+’ …S¼swydh|¹ìÎoˆ}%¢j{Ð>×íÙ”«Xµ Ç ¼ø1a^vV8'áeš#?U4 àq6vB]›òÍb~h°=-½ÞAƒ ¹TúTRQ•·v¯=²Fÿ~à~xÜïÕb0òþE-܇¡¥« õfYßMåmÝ“%ßÈ@½ý*»"¦ð™Ñß-$V¨_'žYùu<|½RWð<º'Z±¯àåõ^‡rÕRÏ= ûwš2xBS‚_×”"sqlDåq Ç ¤Èѱ#¤Nv¡Õå·ß\¢Î£–q«Ÿ;F5!õ~þðÙröà€³{½ŸãìÀâëàë®v»%ê¶2åªó§‘X~FÙ—xPÚp­ªwE_ð¨9ݽîG>nCzöPK`”]@6¾Þz² xl/sharedStrings.xmlmÁŠ1Dï~EèûšÙ‘$sÜhœÖ L:³éÑ¿7ËñXïQPåÚ[Í•ŠÄÌ>— âSî#_<ü»5QäÇÌäáNmX85µÊâaP6ÖÊi „²Ìq5ç\jåbe*„½ DšFûÕ4ß6ad03Çß™¶yfõ°‚à$§¡‹E”1‘³œýƒÿbïùa¨ã^a‡·W´³#±šö©lýPK`”]@Q¹9Cþ§ xl/styles.xml­TMoœ0½÷WX¾7ì®Ôª€¨„ÔC£ªÙJ½X+þ@ö°eóë;¶ °J¤^ÊÅ3oÆoìÇŒó»I+vç¥5ßßì8ÓØVš¾à¿ŽÕûOœy¦Ê(ø<¿+ßå/ OȈáÖ¢¡èàÀƒ; ñ?!·Yæ›háoì†"uZ ¹®Ï<í­LZe‡Ýîc¦…4¼Ìͨ+ž5v4XðÏʼ³fEö<”*4°³P¿JÖN†\ÿœ ý>xur"‹ÜØc² Ý.nB'Ÿ`o¬²Ž¹¾.xUíâà,Ž‹§cH¥–sxÊ|ˆàLE›íãe€¹eõ÷[úôÅÓ^6u7”¡|\þQ¬wâ²?|øõâB·®­k©u¶ÿ#Aaã$A©ÇÐ.¿»«Ô©cékƒÖ,Hùbÿl&šäÚ-[â~M;u¯)¯K½ÍÏÄ0¨KeS»%ïaÔ5¸*vì&‡VïkäXý/JöFC¢)sñⲓuò™èCwõ`À ÅÃô¡lT[D«9C˜ð§Eq(‰õÑÀ‚wBy/rÒ<m%,ˆ3u³B‹8Qª+}”…©)øC¸c­¥Biސœ8Û©»žH5=©J ¨à«ýZ9êÏü%ë‡<[œ³¢½¦ÆÍÖ'¦ü PK`”]@)¥ -—Áxl/workbook.xmlQ]O1|ﯰü^î‚ÔFqZJ‹ÔTRúìØ{Ü ÉëK€_ßµChyëÓzvwÆžñêüÁ;±ƒLƒ’³“^ &Z wJþÚ\¾}'¬v1€’@ò|ýfµù~ã½`þ’’6\„H¥Šæó¯qÉ¥î",ÍÿÄÀ<—\aV— ]Ä€âŽz²…¬,K“áÞ¤ ÖNI ÷&²uYróz ÷Ô:끹-œâ4‰?!)¸W)2¯Øùbyn„ ¿$ìíè9¾y™B{¹6ˆ;Oþ ˆd¶î¿)n©’Ê™Zð÷—¨nHz–Iã4ë µ! çµräu]åG³ÓuÞBêÁ·8Ÿb”Äc}WÜñ41¸L«FÅý.–'$_æÁsB)¼—³IçIÜP]YÇ]Œ¹Å”»sGSîjÌO¹ë1÷eàbª±W¤-º{$t$¸¡`¯XΕ%Mqó›p;Ø6͍ÄÒÓ%(õCU—ú=Jj ©iæ?\lÑ\¼y­ÀÐì„ Iqð>B‹N"Ø0R·˜í@L«µh óÚáZ*f€*Ù {âï£=kõ1ÍDe¤vwUØ¡h{˜ÓÎy@½Òax½ßÂOn¶Ôj¤ 'f>;e‘iç2œVáDºAç°ì­" ¼·Ž½Îèz£‹K‰ê*ª8É÷(ß Ì(I}źEðÌ•çç4ð¹tO8,Fg¿HáŠn³Ú´ë/2ÏÁPÈ;!®ЇÇ艵4֍F‰2½HWÐçÓ¯0Wr«=Ö ÑáôóÑ.5 ïèLÇ6{ ÷gÚP=\þ<8ŒÜ—6¸L¬` NSk,™ÃÇžþPK`”]@ÍKR"x#xl/worksheets/_rels/sheet1.xml.relsMŒ1!{_A¶÷@ cÌq×ù£Øp+a!,1ú{)-'“™yýä¤ÞÔ$¶p˜ (bW¶ÈÞÂã~ÝŸAIGÞ0& _X—Ý|£„}4b5&,Bïõ¢µ¸@e*•x˜giûÀæuE÷BOúhÌI·ÿèåPK`”]@G’D²Xð[Content_Types].xmlPK`”]@¶78éK ‰_rels/.relsPK`”]@„$±Vé¹›xl/_rels/workbook.xml.relsPK`”]@×Íê†;¼docProps/app.xmlPK`”]@÷yà£rpdocProps/core.xmlPK`”]@­­áJxl/theme/theme1.xmlPK`”]@6¾Þz² Œ xl/sharedStrings.xmlPK`”]@Q¹9Cþ§ p xl/styles.xmlPK`”]@)¥ -—Á™xl/workbook.xmlPK`”]@ÉÐåØ©]xl/worksheets/sheet1.xmlPK`”]@ÍKR"x#<xl/worksheets/_rels/sheet1.xml.relsPK Ñõ

Feb 29, 2012 at 2:21 PM

I can imagine. So what  exactly is your problem? your code seems to output the Excel sheet as desired!

Coordinator
Feb 29, 2012 at 5:16 PM

No headers to tell the browser that the output is an xlsx file.

// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');

 as per /Tests/01simple-download-xlsx.php

Mar 1, 2012 at 5:48 AM

MarkBaker thanks.

  Issues solved.