Skip to content

Instantly share code, notes, and snippets.

@manchumahara
Created September 23, 2022 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manchumahara/f2d72e8eb5beb8808cfe636bf8b983d5 to your computer and use it in GitHub Desktop.
Save manchumahara/f2d72e8eb5beb8808cfe636bf8b983d5 to your computer and use it in GitHub Desktop.
phpexcel next column prev column letter
/**
* Next letter for excel
*
* @param string $current_letter
*
* @return string
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
function excel_next_letter($current_letter = 'A')
{
$columnAlpha_index = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($current_letter);
$letter = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($columnAlpha_index + 1);
return $letter;
}//end excel_next_letter
/**
* Previous letter for excel
*
* @param string $current_letter
*
* @return string
* @throws \PhpOffice\PhpSpreadsheet\Exception
*/
function excel_prev_letter($current_letter = 'A')
{
$columnAlpha_index = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::columnIndexFromString($current_letter);
$letter = \PhpOffice\PhpSpreadsheet\Cell\Coordinate::stringFromColumnIndex($columnAlpha_index - 1);
return $letter;
}//end excel_prev_letter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment