Page 1 of 1

GET_EXCEL_COLUMN_ID returns wrong column ID

Posted: Wed Mar 09, 2016 2:33 pm
by SvenVazan
Hey Roger,

I'm not sure if this is documented anywhere, but the supporting function GET_EXCEL_COLUMN_ID() does not return the correct Excel columns value for any columns ending with a 'Z' (AZ, BZ, CZ, ...).

For example, 52nd column, which should return value 'AZ', returns 'B' instead.

Quick suggested fix:

Code: Select all

FUNCTION Get_Excel_Column_ID( i )
LOCAL cAlpha := "ABCDEFGHIJKLMNOPQRSTUVWXYZ", cLastRow := ""

IF i > 26
  IF Mod(i,26) = 0
    cLastRow := Substr(cAlpha,Int((i-1)/26),1) + Substr(cAlpha,26,1)
  ELSE
    cLastRow := Substr(cAlpha,Int(i/26),1) + Substr(cAlpha,Mod(i,26),1)
  ENDIF
ELSE
  cLastRow := Substr(cAlpha,i,1)
ENDIF

RETURN cLastRow
Thanks!

Re: GET_EXCEL_COLUMN_ID returns wrong column ID

Posted: Thu Mar 10, 2016 12:46 pm
by rdonnay
Sven -

Thank you for that fix.

I added it to my source and it will be in build 264.

Roger