Skip to content

Instantly share code, notes, and snippets.

@n5i
Created February 14, 2013 17:58
Show Gist options
  • Save n5i/4954731 to your computer and use it in GitHub Desktop.
Save n5i/4954731 to your computer and use it in GitHub Desktop.
PHPExcel - break links to other sheets
// Replace calculated values with static data. From A to H from 1 to 70
function breakExcelLinksInSheet( $sheet ){
$labels = array( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H' );
foreach( $labels as $label ){
for( $i = 1; $i < 70; $i++ ){
$val = $sheet->getCell( $label.$i );
//for incorrect formulas take old value
if( ( substr( $val, 0, 1 ) === '=' ) && ( strlen( $val ) > 1)){
$value = $sheet->getCell( $label.$i )->getOldCalculatedValue();
$sheet->setCellValue( $label.$i, $value );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment