Hello forum,
I have excel file with this pattern:
ID #1 #2 #3
NAME A B C
#1 A x
#2 B x
#3 C x
ID #1 #2 #3
NAME A B C
#1 A x
#2 B x
#3 C x
To copy to clipboard, switch view to plain text mode
"X" means that the row belongs to the column.
sheet = nullptr;
sheets = nullptr;
workbook = nullptr;
workbooks = nullptr;
excelApplication = nullptr;
if(path == "")
{
qDebug() << "'fileName' is empty!";
return;
}
path.replace("/", "\\");
excelApplication
= new QAxObject( "Excel.Application",
0 );
if (excelApplication == nullptr)
throw invalid_argument("Failed to initialize interop with Excel (probably Excel is not installed)");
excelApplication->dynamicCall( "SetVisible(bool)", false ); // hide excel
excelApplication->setProperty( "DisplayAlerts", 0); // disable alerts
workbooks = excelApplication->querySubObject( "Workbooks" );
workbook = workbooks->querySubObject( "Open(const QString&)", path );
sheets = workbook->querySubObject( "Worksheets" );
...
...
for(int i=0; i<rowsCnt; ;++i)
for(int j=0; j<colsCnt; ;++j)
{
QAxObject* cell
= sheet
->querySubObject
( "Cells( int, int )", i, j
);
QVariant value
= cell
->dynamicCall
( "Value()" );
dataRow.append(value);
}
QString path = fileName;
sheet = nullptr;
sheets = nullptr;
workbook = nullptr;
workbooks = nullptr;
excelApplication = nullptr;
if(path == "")
{
qDebug() << "'fileName' is empty!";
return;
}
path.replace("/", "\\");
excelApplication = new QAxObject( "Excel.Application", 0 );
if (excelApplication == nullptr)
throw invalid_argument("Failed to initialize interop with Excel (probably Excel is not installed)");
excelApplication->dynamicCall( "SetVisible(bool)", false ); // hide excel
excelApplication->setProperty( "DisplayAlerts", 0); // disable alerts
workbooks = excelApplication->querySubObject( "Workbooks" );
workbook = workbooks->querySubObject( "Open(const QString&)", path );
sheets = workbook->querySubObject( "Worksheets" );
...
...
for(int i=0; i<rowsCnt; ;++i)
for(int j=0; j<colsCnt; ;++j)
{
QAxObject* cell = sheet->querySubObject( "Cells( int, int )", i, j);
QVariant value = cell->dynamicCall( "Value()" );
dataRow.append(value);
}
To copy to clipboard, switch view to plain text mode
It works fine, but the execution time is slow, especially at a larger table (200x200 or more).
My question is if exist faster way to read excel file.
Thanks for any advice!
Bookmarks