Thursday, 15 January 2015

php - How to Delete/Remove Graphs(charts), Pictures(Images) from excel file loaded into PHPExcel? -



php - How to Delete/Remove Graphs(charts), Pictures(Images) from excel file loaded into PHPExcel? -

i using phpexcel class , loading template speadsheets , modifying info , forth.

depending on pass script dynamically, images in template should remove , graphs(charts) should removed.

i have used getchartcollection() , getdrawingcollection() havent figured out way modify collections can remove charts, and/or images loaded template.

thanks help. jason k.

update - info mark baker below. wrote next code needs added worksheet class until 1.7.9 released. code below.

/** * remove drawing collection * * @return phpexcel_worksheet_basedrawing[] */ public function removeimagebyids($ids) { if(!is_array($ids)) $ids = array($ids); $drawing_collection = $this->_drawingcollection; $drawing_collection_copy = $drawing_collection->getarraycopy(); foreach($ids $id){ unset($drawing_collection_copy[$id]); } $drawing_collection_copy = array_values($drawing_collection_copy); $drawing_collection->exchangearray($drawing_collection_copy); $this->_drawingcollection = $drawing_collection; unset($drawing_collection_copy); unset($drawing_collection); homecoming $this->_drawingcollection; } /** * remove chart collection * * @return phpexcel_worksheet_basedrawing[] */ public function removechartbyids($ids) { if(!is_array($ids)) $ids = array($ids); $chart_collection = $this->_chartcollection; $chart_collection_copy = $chart_collection->getarraycopy(); foreach($ids $id){ unset($chart_collection_copy[$id]); } $chart_collection_copy = array_values($chart_collection_copy); $chart_collection->exchangearray($chart_collection_copy); $this->_chartcollection = $chart_collection; unset($chart_collection_copy); unset($chart_collection); homecoming $this->_chartcollection; }

enjoy. jason k.

believe or not, first time has ever asked removing charts or images spreadsheet. phpexcel doesn't have methods this, they'd easy plenty add together yourself. methods add together entries in these collections in phpexcel_worksheet class; , collection array, it's case of using unset(), array_splice() or similar remove entries don't want.

php phpexcel

No comments:

Post a Comment