我试图将一个excel文件(只有像矩阵这样的数字)导入我的Qtableview!我在网上发现了一些与QtableWidget相关的代码,但我认为它适用于QtableView 提前谢谢
答案 0 :(得分:0)
尝试使用QAxObject - 提供一个包装COM对象的QObject: 像这样:
QAxObject *excel = new QAxObject ("Excel.Application", 0);
//excel->dynamicCall ("SetVisible(bool)", true);
QAxObject *workbooks = excel->querySubObject ("Workbooks");
workbook = workbooks->querySubObject ("Open(const QString&)", fileName);
QAxObject *statSheet = sheets->querySubObject ("Item(const QVariant&)", QVariant (sheetsComboBox->currentText ()));
statSheet->dynamicCall ("Select()");
int column = 0;
int summe_column = 0;
int col = 1;
do
{
QAxObject* cell = statSheet->querySubObject ("Cells( int, int )", 1, col );
QVariant value = cell->dynamicCall( "Value()" );
QString string = statSheet->querySubObject ("Cells( int, int )", row, column)->dynamicCall( "Value()" ).toString();
++col;
}
while (col < 40)
}
你的.pro文件中还需要CONFIG + = qaxcontainer。