problem with reader of excel5

Topics: Developer Forum, User Forum
Sep 24, 2008 at 3:56 PM
hi all,

    i am using
       
$objReader = new PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load(SGL_MOD_DIR . "/sample/classes/Sample.xls");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('C9', 'Sample Order');//test if i can edit
$objWriter->save('test.xls');

but it seems the image in the original file is missing.


George
Developer
Sep 24, 2008 at 4:15 PM
I'm afraid that PHPExcel_Reader_Excel5 is currently not reading images, but the problem has been addressed. There are still a couple of hurdles.

http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=7538

If you need this feature for spreadsheet manipulation from template, the solution for you may be to use Excel 2007 template instead of Excel 2003 template. Convert your Sample.xls to Sample.xlsx using MS Office Excel 2007 or MS Office Excel 2003 with SP3 + compatibility pack. PHPExcel_Writer_Excel5 supports images so you can still create xls files with images.

Related discussion (reading Excel 2007 files with images):
http://www.codeplex.com/PHPExcel/Thread/View.aspx?ThreadId=35045
Sep 25, 2008 at 10:54 AM
got it.thanks very much.

i have one more related question:

will the page setting be kept after load(i mean excel5)?
it seems both image and page setting is missgin when i read from xls and save as xls.



Developer
Sep 25, 2008 at 11:03 AM
PHPExcel_Reader_Excel5 does recognize a good deal of page setup properties. This includes paper size, orientation, page margins, header / footer etc. But these features were added recently so to get this working you will need to latest source of PHPExcel (1.6.3 won't do).
Download latest source from here:
http://www.codeplex.com/PHPExcel/SourceControl/ListDownloadableCommits.aspx
Sep 25, 2008 at 11:24 AM
I have get a lastest version,thanks!

Can the xlsx template work like php template tech,that we put some tag in the template file,
and it then will be merged with variable data?

thanks for your reply!!


Developer
Sep 25, 2008 at 11:53 AM
It may not be that hard to get what you want.

Example:

// 2007-read.xlsx contains cells where one has typed "tags" [CUSTOMER_NAME] or [EMAIL]
$customerName = 'John Smith';
$email = 'john@example.org';

$objReader = new PHPExcel_Reader_Excel2007();
$PHPExcel = 
$objReader->load('2007-read.xlsx');
$ws = $PHPExcel->getActiveSheet();

foreach ($ws->getCellCollection() as $cell) {
    switch ($cell->getValue()) {
   
    case '[CUSTOMER_NAME]':
        $cell->setValue($customerName);
        break;
       
    case '[EMAIL]':
        $cell->setValue($email);
        break;
   
    default:
        break;
       
    }
   
}

$objWriter = new PHPExcel_Writer_Excel2007($PHPExcel);
$objWriter->save('2007-write.xlsx');