How to refer to a cell in R1C1 style

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • How to refer to a cell in R1C1 style

    Hi all,

    in order to write data from an odbc_exec into the spreadsheet, i want to iterate a cell range with a nested loop. The question i came across is, how can i refer to a single cell in an VBA-like style to refer to something like

    PHP Source Code

    1. activesheet()->range($rowNum, $fieldNum)->value = odbc_result($rs,$fieldNum)

    I really don´t want to have a mapping array in order to map the letters from A - ZZ to numbers and then glue them together to a A1-style reference. Does anybody know of a way to do it?

    thanks & regards
  • Hi OMartin,

    with this function you can query the number of the colum :

    PHP Source Code

    1. function getNumber($letter)
    2. {
    3. $number=0;
    4. for ($let='A';$let<'ZZ';$let++)
    5. {
    6. $number++;
    7. if ($let==$letter)
    8. {
    9. return $number;
    10. }
    11. }
    12. }
    Display All

    it exploits a weird feature of PHP that is, iterate on letters 8|

    Post hoc, non est propter hoc
  • Thanks Laloune,

    works fine. But despite of my initial dislike of setting up an array, now i start to wonder, if an array would be more recommendable if it comes to very high numbers of cells to be referred to.

    Let´s say i want to iterate over a couple thousand cells, would you expect accessing an array to be significantly faster than your loop?