Excel with Qt:find number last filled row [英] Excel with Qt: find number last filled row

查看:159
本文介绍了Excel with Qt:find number last filled row的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Qt中打开了excel表,并尝试使用这段代码来获取行数和列数(如果全部填充):

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆