Excel with Qt:find number last filled row [英] Excel with Qt: find number last filled row
问题描述
QString file = QFileDialog :: getOpenFileName(这是打开文件);
QAxWidget excel(Excel.Application);
excel.setProperty(Visible,true);
QAxObject * workbooks = excel.querySubObject(WorkBooks);
QAxObject * workbook = workbooks-> querySubObject(Open(const QString&)),file);
sheets = workbook-> querySubObject(Worksheets);
QAxObject * sheet = sheets-> querySubObject(Item(int),i);
QAxObject * rows = sheet-> querySubObject(Rows);
int rowCount = rows-> dynamicCall(Count()).toInt();
QAxObject * columns = sheet-> querySubObject(Columns);
int columnCount = columns-> property(Count)。toInt();
ui-> label-> setText(QString :: number(rowCount)+,+ QString :: number(columnCount));
}
问题是rowcount,coulumnCount显示大量,我的工作表已填写4x6。我已经看到这些问题:
以程序方式获取Excel列的最后一个非空单元格
在c#中查找Excel工作表中最后一个填充的行
但两者都是针对C#
但是我不知道如何在Qt中执行此操作
我已经解决了Excel.Range和UsedRange的问题(在这种情况下,所有单元格都应该连续填充在空单元格之间将被计算)
QAxObject * sheet = sheets-> querySubObject(Item(int),i);
QAxObject * range = sheet-> querySubObject(UsedRange);
QAxObject * rows = range-> querySubObject(Rows);
int rowCount = rows-> dynamicCall(Count()).toInt();
QAxObject * columns = range-> querySubObject(Columns);
int columnCount = columns-> property(Count)。toInt();
ui-> label-> setText(QString :: number(rowCount)+,+ QString :: number(columnCount));
I have opened excel sheet in Qt and trying to get number of rows and columns filled (if all filled continuous) with this code :
QString file = QFileDialog::getOpenFileName(this,"Open file");
QAxWidget excel("Excel.Application");
excel.setProperty("Visible", true);
QAxObject * workbooks = excel.querySubObject("WorkBooks");
QAxObject* workbook = workbooks->querySubObject( "Open(const QString&)", file );
sheets = workbook->querySubObject( "Worksheets" );
QAxObject* sheet = sheets->querySubObject( "Item( int )", i );
QAxObject* rows = sheet->querySubObject( "Rows" );
int rowCount = rows->dynamicCall( "Count()" ).toInt();
QAxObject* columns = sheet->querySubObject( "Columns" );
int columnCount = columns->property("Count").toInt();
ui->label->setText(QString::number(rowCount)+" ," +QString::number(columnCount));
}
The problem is rowcount and coulumnCount is showing a large number but my sheet have 4x6 filled.
I have seen these questions : Get Last non Empty Cell of Excel Column Programatically
Finding the last filled row in Excel sheet in c#
but both are for C# But i dunno how to do this in Qt
I have solved the problem with Excel.Range and UsedRange (it is not necessary that all cells should be continuously filled in this case in between empty cells will be counted)
QAxObject* sheet = sheets->querySubObject( "Item( int )", i );
QAxObject * range = sheet->querySubObject("UsedRange");
QAxObject * rows = range->querySubObject( "Rows" );
int rowCount = rows->dynamicCall( "Count()" ).toInt();
QAxObject* columns = range->querySubObject( "Columns" );
int columnCount = columns->property("Count").toInt();
ui->label->setText(QString::number(rowCount)+" ," +QString::number(columnCount));
这篇关于Excel with Qt:find number last filled row的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!