How to get number of used columns in a row in QXlsx
-
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.
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.
-
@MrDkman
There isn't (or I can't find!) any documentation onQXslx
:( 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.
-
@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.
-
@JonB well regarding getting the first column/row there's a function the will return the first column/row
you can get it usingdoc.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, -
@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?
-
@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?