Idea to make use easier

Topics: Developer Forum
May 23, 2008 at 5:51 AM
Hello,

what if....  this was packaged a little different?
The thing I love about this,  is I can allow my users to choose their formats (PDF, Excel 97-2003, Excel 2007, CSV, HTML.... and more to come)

but currently we do this:
include("PHPExcel/Writer/Excel2007.php");
$objPHPExcel = new PHPExcel();
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save('php://output');

So in order not to repeat my self,  I have export_report.php?type=[what they want] and now I have to riddle my report(s) with if statements every time...
at the top
if ($type == "Excel2007"){
include("PHPExcel/Writer/Excel2007.php");
}else if{ else if{ else if{}

and at the bottom
if ($type == "Excel2007"){
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
}else if{ else if{ else if{}

and if another format is ever added to the library I have to go back and update all my report pages

what if we had 
include("PHPExcel/somefile.php");
$objPHPExcel = new PHPExcel("$Type Goes HERE");
$objWriter = new PHPExcel_Writer($objPHPExcel);
$objWriter->save('php://output');

and let the system automagicly include the files,  and automagicly include the correct writter class?

Not sure how to do this,  otherwise I would and contribute it.... but it may be worth looking at....
Coordinator
May 23, 2008 at 7:08 AM
What would you think of a PHPExcel_WriterFactory?

Some example pseudo code:
{{
include("PHPExcel.php");
$objPHPExcel = new PHPExcel();
$objWriter = PHPExcel_WriterFactory("Excel2007");
$objWriter->save('php://output');
}}

or

{{
include("PHPExcel.php");
$objPHPExcel = new PHPExcel();
$objWriter = PHPExcel_WriterFactory("Excel5");
$objWriter->save('php://output');
}}
Coordinator
May 23, 2008 at 7:21 AM
Added a work item for this: http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=6227
May 23, 2008 at 7:46 AM
thank you.