How to refer to a cell in R1C1 style

    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
    OMartin
    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. }


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

    Post hoc, non est propter hoc
    challenge accepted.

    PHP Source Code

    1. function getLetter($number)
    2. {
    3. $currNumber=0;
    4. for ($let='A';$let<='ZZ';$let++)
    5. {
    6. $currNumber++;
    7. if ($number==$currNumber)
    8. {
    9. return $let;
    10. }
    11. }
    12. }
    13. echo getLetter(256);
    14. // returns "IV"
    laloune

    Post hoc, non est propter hoc

    Post was edited 1 time, last by “laloune” ().

    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?

    cheers
    OMartin