Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. How to get number of used columns in a row in QXlsx
Forum Updated to NodeBB v4.3 + New Features

How to get number of used columns in a row in QXlsx

Scheduled Pinned Locked Moved Solved 3rd Party Software
8 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrDkman
    wrote on last edited by
    #1

    I have an excel file that I'm trying to parse in Qt Framework using QXlsx library. I'm Stuck on calculating the number of last Used column in a row, because each row has a different number of used columns. see the picture below as an example.
    alt text

    I have already tried the following code

    QXlsx::Document doc("data.xlsx");
    int lastColumn = doc.dimention().columnCount();
    

    But this line will return the number of last used column in the excel file in my example it will be column 'F' which will be 6 for all rows which is incorrect.

    Any hint will be appreciated Thanks in advance.

    JonBJ 1 Reply Last reply
    0
    • M MrDkman

      I have an excel file that I'm trying to parse in Qt Framework using QXlsx library. I'm Stuck on calculating the number of last Used column in a row, because each row has a different number of used columns. see the picture below as an example.
      alt text

      I have already tried the following code

      QXlsx::Document doc("data.xlsx");
      int lastColumn = doc.dimention().columnCount();
      

      But this line will return the number of last used column in the excel file in my example it will be column 'F' which will be 6 for all rows which is incorrect.

      Any hint will be appreciated Thanks in advance.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @MrDkman
      There isn't (or I can't find!) any documentation on QXslx :( Just some examples, if those don't cover your question you're on your own. Looking at the source code is your friend :)

      As far as I can see dimension() is only a method of a worksheet. I do not see anything per row. And I'm not sure Excel would give you what you want for this.

      So, unless you find something better, I can only suggest: you know the maximum number of columns in the worksheet. Go to a row. Iterate backwards from the maximum column, moving over all trailing "empty" cells. When you come to a non-empty cell, that's your last used column in that row.

      1 Reply Last reply
      1
      • M Offline
        M Offline
        MrDkman
        wrote on last edited by
        #3

        @JonB thank you very much for the hint it works!!!
        I'm really ashamed that I have been stuck for a hole day and didn't think about it!

        JonBJ 1 Reply Last reply
        0
        • M MrDkman

          @JonB thank you very much for the hint it works!!!
          I'm really ashamed that I have been stuck for a hole day and didn't think about it!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @MrDkman
          I suspect that Excel itself, and for that matter QXlsx, probably does not bother maintaining any list of what the first/last column is in each row (nor probably what the first/last rows are). I would have thought they let you put something into whatever row/column you like anywhere, and maybe note what the highest is while in memory or after loading from file.

          So.... my thought is to find what you want you just have to do your own look in each row and decide what the last used column is for yourself.

          M 1 Reply Last reply
          0
          • JonBJ JonB

            @MrDkman
            I suspect that Excel itself, and for that matter QXlsx, probably does not bother maintaining any list of what the first/last column is in each row (nor probably what the first/last rows are). I would have thought they let you put something into whatever row/column you like anywhere, and maybe note what the highest is while in memory or after loading from file.

            So.... my thought is to find what you want you just have to do your own look in each row and decide what the last used column is for yourself.

            M Offline
            M Offline
            MrDkman
            wrote on last edited by
            #5

            @JonB well regarding getting the first column/row there's a function the will return the first column/row
            you can get it using

            doc.dimition().firstRow();
            doc.dimition().firstColumn();
            

            But for getting the last used column actually I found some walk around to get it in C++ in windows using Excel API's

            I really appreciation the hint
            Cheers,

            JonBJ 1 Reply Last reply
            0
            • M MrDkman

              @JonB well regarding getting the first column/row there's a function the will return the first column/row
              you can get it using

              doc.dimition().firstRow();
              doc.dimition().firstColumn();
              

              But for getting the last used column actually I found some walk around to get it in C++ in windows using Excel API's

              I really appreciation the hint
              Cheers,

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @MrDkman
              I get that, but I wonder if that is not stored with the worksheet, only calculated on load.

              But for getting the last used column actually I found some walk around to get it in C++ in windows using Excel API's

              I'd be interested to know what functions you found?

              M 1 Reply Last reply
              0
              • JonBJ JonB

                @MrDkman
                I get that, but I wonder if that is not stored with the worksheet, only calculated on load.

                But for getting the last used column actually I found some walk around to get it in C++ in windows using Excel API's

                I'd be interested to know what functions you found?

                M Offline
                M Offline
                MrDkman
                wrote on last edited by
                #7

                @JonB see this answer I found on stack overflow

                JonBJ 1 Reply Last reply
                1
                • M MrDkman

                  @JonB see this answer I found on stack overflow

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @MrDkman
                  Thanks! Glancing through all those replies, and comments about deleted cells, dirty cells, special cells... looks nasty, doesn't it!? And it doesn't look as though any of those were going to provide your "last used column per each individual row", does it?

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved