Results 1 to 10 of 10

Thread: Creating Column numbering like in Excecl i.e. A...Z then AA ... ZZ and so forth

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    22
    Thanked 19 Times in 16 Posts

    Default Creating Column numbering like in Excecl i.e. A...Z then AA ... ZZ and so forth

    Hi,
    I wanted to have a numbering scheme for columns like the one provided by Office calculation programs.

    My approach so far is this:

    Qt Code:
    1. #include <QList>
    2. #include <QStringList>
    3. #include <QDebug>
    4.  
    5. QString getLabelFromInt(uint digit)
    6. {
    7. uint base = 26;
    8.  
    9. uint remainder;
    10. uint quotient = digit;
    11.  
    12. QList<int> l;
    13. do {
    14. remainder = quotient % base;
    15. quotient = quotient / base;
    16. l.prepend(remainder);
    17. } while (quotient != 0);
    18.  
    19. QStringList strList;
    20. for (int i = 0; i < l.size(); ++i)
    21. strList << QString(char(l[i] + 'a'));
    22.  
    23. return strList.join("");
    24. }
    25.  
    26. int main(int argc, char** arg) {
    27. for (int i = 0; i < 200; ++i)
    28. qDebug() << getLabelFromInt(i);
    29. }
    To copy to clipboard, switch view to plain text mode 
    but it generates a-z but then continues with ba - zz and then baa - zzz. Considering an alphabet with two symbols (0 and 1) it would have to go like this:

    0
    1
    00
    01
    10
    11
    000
    001
    010
    011
    100
    101
    110
    111

    instead of
    0
    1
    10
    11
    100
    101
    110
    111

    Of course I see the pattern: the first one has 2^3+2^2+2^1 elements (since it includes the preceding combinations) while the second (normal) one has 2^3 elements but I can't put the pieces together.
    Is there a simple way to implement this?

    Thanx in advance
    momesana
    Last edited by momesana; 3rd December 2009 at 16:44.

Similar Threads

  1. Replies: 0
    Last Post: 10th November 2006, 13:46
  2. hidden QListView column suddenly visible
    By edb in forum Qt Programming
    Replies: 10
    Last Post: 27th January 2006, 08:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.