Problem with read xlsx template file and save as new. HELP :)

Topics: Developer Forum, User Forum
Nov 4, 2011 at 11:06 AM

Hello,

its my first discussion on this site ;) 

 

So my problem is:

I work on some site, and i need to create statistics in xlsx file.

So i decided create a template xlsx file 'template.xlsx'. Load this file, insert some data into that, and finally save as NEW xlsx file 'output.xlsx' wich wil be able to download by user.

I have problem with output.xlsx. its look little bit oddly...

code:

 

error_reporting(E_ALL);

date_default_timezone_set('Europe/London');

/** PHPExcel */
require_once '../Classes/PHPExcel.php';
/*
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$obj = $objReader->load("totest.xlsx");
$obj->setActiveSheetIndex(0);
$obj->getActiveSheet()->setCellValue('C2', '40');

*/

$reader = new PHPExcel_Reader_Excel2007();

$obj = $reader->load('totest.xlsx');
$obj->setActiveSheetIndex(0);
$obj->getActiveSheet()->setCellValue('C2',40);

$objWriter = PHPExcel_IOFactory::createWriter($obj, 'Excel2007');
$objWriter->save('output.xlsx');

$obj->disconnectWorksheets();

 

 

Printscreen:

template.xlsx

http://img850.imageshack.us/img850/5053/beforec.png

output.xlsx

http://img638.imageshack.us/img638/3448/afterk.png

 

 

Please help :)