Generate XML file onfliy

Aug 25, 2008 at 3:30 PM
Hy,

stupid question from buddy user:

"how I can create a symple XML file and download it onfly?"

I've try to use the header properties but the test code generate the file on the server.

Somoeon can help me?
Developer
Aug 25, 2008 at 3:46 PM
Do you mean XML? Or Excel?
Aug 25, 2008 at 4:02 PM
Sorry, I have a php script to generate an html table.
I need to export this table, both text and images, on a xls file (office 2000).
I I simply use the mime info i can open the html table in xls, but i can't insert images. I need to use PHPExcell componet for the images.
I know VERY little XML an Excel!
Developer
Aug 25, 2008 at 5:44 PM
So you are using the Excel5 writer? Maybe you need to show us some of you code. What is it that is not working?
Aug 26, 2008 at 7:22 AM
I'm using the test file 05featuredemo.php.  I see it' call an inc. file for build data, the 05featuredemo.php file just write the file on disk.

I want to change it for download the file without writing it.

the 05featuredemo.php code:

include "05featuredemo.inc.php";
 
/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';
 
// 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__));
 
// Echo memory peak usage
echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
 
// Echo done
echo date('H:i:s') . " Done writing file.\r\n";

The generator code in the inc file is easy to understand, wat I don't know an I don't understand from the documentation is how to put the component output to the browser.

Thanks!
Aug 26, 2008 at 8:26 AM
I'm try to use:

header("Pragma: public");
header("Expires: 0");
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=prova.xlsx");
header("Content-Transfer-Encoding: binary ");

//some function to generate the xls//

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("php://output");
I can download the file but i can't read it. In the file properties i see "application/download" filetype, if I opentit in OpenOffice Calc I see a blank spreadsheet whit the first cell A1 called "HTML_all"...

Aug 26, 2008 at 9:40 AM
woah! I'ved fix:

header("Pragma: public");
header("Expires: 0");
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/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment;filename=prova.xlsx");
header("Content-Transfer-Encoding: binary ");


/** Error reporting */
error_reporting(E_ALL);

/** Include path **/
set_include_path('/PHPExcell/Classes/');
/** PHPExcel */
include 'PHPExcel.php';

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
$objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");
$objPHPExcel->getProperties()->setCategory("Test result file");


// Add some data
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello');
$objPHPExcel->getActiveSheet()->setCellValue('B2', 'world!');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Hello');
$objPHPExcel->getActiveSheet()->setCellValue('D2', 'world!');

// Add a drawing to the worksheet
//echo date('H:i:s') . " Add a drawing to the worksheet\n";
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('PHPExcel logo');
$objDrawing->setDescription('PHPExcel logo');
$objDrawing->setPath('../images/phpexcel_logo.gif');
$objDrawing->setHeight(36);
$objDrawing->setCoordinates('D4');
$objDrawing->setOffsetX(-10);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());

// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');


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

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("php://output");