Skip to content

Instantly share code, notes, and snippets.

@tamura
Forked from anonymous/mergedcellvalue
Last active August 29, 2015 13:58
Show Gist options
  • Save tamura/10343637 to your computer and use it in GitHub Desktop.
Save tamura/10343637 to your computer and use it in GitHub Desktop.
## usage:
## PHP Excel
## $objPHPExcel->setActiveSheetIndex(1);
## $objSheet = $objPHPExcel->getActiveSheet();
## mergedcellvalue($objSheet, "B2");
function mergedcellvalue($objSheet, $cell)
{
foreach ($objSheet->getMergeCells() as $key => $cellarea) {
if($objSheet->getCell($cell)->isInRange($cellarea)){
return $objSheet->getCell(array_shift(explode(":", $cellarea)))->getValue();
}
}
return $objSheet->getCell($cell)->getValue();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment