How to find the Range of Cell in excel - Qt? - c++

I have cell's value as row and column.
Cells(1,10); //1 is row and 10 is column
Now i want to identify the Range of of that cell location.
J1; //where j is column and 1 is row
Is there any possibility to find out in QT?

Using the object model
Cells(5, 3).address(true,true,xlA1)
would return "$C$5"

Related

QTableWidget::resizeRowsToContents() does not work for rows with column spans

I develop a project that uses QTableWidget. Below is a small test fragment of code reproducing the problem.
auto tw = new QTableWidget(3,3);
tw->setItem(0, 0, new QTableWidgetItem("test123 test123 test123 test123 test123 test123 test123"));
for (int i = 1; i < 3; ++i)
for (int j = 0; j < 3; ++j)
tw->setItem(i, j, new QTableWidgetItem("test123"));
tw->setSpan(0,0,1,3);
tw->show();
tw->resizeRowsToContents();
There is a table with 3 rows and 3 columns. The first cell of the table contains a long text. I create a column span at this cell to fit the text and avoid changing other columns width.
The issue is occured when I try to resize rows to their contents. All rows except the first one is resized without any problems - they take up minimal space. The first one gets much more higher that it was before (I expected it to have the same height as the other rows). It seems like QTableWidget::resizeRowsToContents() does not respect column span at all so it increases the row height to fit cell contents.
Could you please tell me how to fix this problem and force rows with column span be resized correctly?

How to grab the last non empty row?

So here's the scenario. In this case i will start at row 2 as starting point. in Column B, i want to record row of the last non empty A column. For example : the first data in B column is 2 which is the very first row then in the next row it will keep that '2' as long as the A column is empty until i reach a value (1) in the A column. When it reach the next non empty row in A column (row 7), then value in B now will keep that value (7) and it will keep that value all the way down until it reach the next non empty row in A , which is row 15. etc. Hope i can explain it clearly.
for now i only use basic formula in B2 cell :
=if( A2<>1, min( row(A2), indirect( "b" & (row(A2) -1) ) ) , row( A2) )
and then copy it down to other cells in B column. It works. But i'm just want to convert this into arrayformula() and got no luck. Does anyone know how to make this works using arrayformula ?
use:
=INDEX(VLOOKUP(ROW(A2:A), {2; FILTER(ROW(A3:A), A3:A<>"")}, 1, 1))
Try this:
=ArrayFormula(vlookup(row(A2:A24),query({row();ArrayFormula(value(substitute(A3:A24,1,row(A3:A24))))},"select * where Col1>0"),1,true))
It has a few stages:
First it takes row number from the first cell using row(). Then it substitutes all 1 cells in column A into corresponding row numbers. Then using query I remove empty or 0 values. I got a small table of:
2
7
15
19
Next stage is to take each row number from a2:a24 and vlookup through my table.
Using vlookup with 'true' parameter it returns nearest value from the table that is smaller than row number tested. So 2 returns 2, 3 returns 2, 4 returns 2, etc.

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.
So after searching and asking for help the way to get the last column in QXlsx library as suggested in this replay is to check for non-empty cell in reverse in each row and break the loop if i found the last non-empty cell. As following
QXlsx::Document doc("data.xlsx");
QVariant cell;
int number;
int lastColumn = doc.dimention().columnCount();
for(int column = lastColumn; 0!=column; column--){
cell = doc.read(row,column);
if(cell.toString()!=""){
number = column;
break;
}
}

Finding index of the maximum value of cube(3d array) using Armadillo library in C++

I am using Armadillo library for the matrix calculation in C++.
And I have one question about finding an index of the maximum value of given 3d arrays.
I found on their website about index_max().
index_max( M, dim )
dim=0, return a row vector, with each column containing the index of the extremum value in the corresponding column of M
dim=1, return a column vector, with each row containing the index of the extremum value in the corresponding row of M
And it seems like, they return the index of the maximum value of each row and column.
But I need an index of the maximum value of the entire matrix.
Does anyone know any way to find an index of the max using Armadillo library?
Thanks in advance.
Instead of the standalone index_max() function, use the .index_max() member function of the matrix or cube. Example:
arma::mat X(100, 200, arma::fill::randu);
arma::uword index = X.index_max();

Number of Items in a Column inside a grid

How do you find number of items in a column inside a grid?
I have a grid (listview control to be specific), and have some items.
Some times a given row might not be full. ANd can have values in fewer than maximum columns. I need to find Number of items in a given Column.
If the grid is like
1 2 3
4 5 6
7
and if input column is 1, then we need to output 3, and 2 for input of 2 or 3.
I have variables to for ItemCount, CoulmnCount and RowCount which track number of items, rows and columns.
A very rudimentar way would be something like this:
int iItemCount=0,iItemInColumn=0;
for(int iCol=0;iCol<iColumnCount;iCol++)
for(int iRow=0;iRow<iRowCount;iRow++,iItemCount++)
if(iCol==iInputCol && iItemCount<iTotalItems)
iItemInColumn++;
Can you guys think of any sophesticated way, which does not need loops? possible utilizing just 3 variables which I already have for tracking?
Assuming 0-based indexes:
def itemsInColumn(itemCount, columnCount, inputColumn):
lastItemColumn = (itemCount - 1) % columnCount
if inputColumn <= lastItemColumn:
return (itemCount + columnCount - 1) / columnCount
else:
return itemCount / columnCount
It depends on the total number of items (itemCount) and the number of columns (columnCount). It just computes itemCount / columnCount, and rounds up or down depending on whether the input column is less than or equal to the last item's column.
The computation "(itemCount + columnCount - 1) / columnCount" is just a trick for rounding up using integer division. In general, given positive integers a and b: ceil(a / b) = (a + b - 1) div b, where div is integer division.