how to find a string in a excel file with qt?
-
Hi
I use lib xlsx in qt for write & read an excel file.
I cann't find the string in my excel file.Thanks for help me.
-
raven-worx Moderatorsreplied to mohsen_yadik on 9 Aug 2017, 10:52 last edited by raven-worx 8 Sept 2017, 11:02
@mohsen_yadik
old (xls) or new (xlsx) format? -
Hi
Im not sure what you have tried..
Did you see the sample ?#include <QtCore> #include "xlsxdocument.h" int main() { { //Create a new .xlsx file. QXlsx::Document xlsx; xlsx.write("A1", "Hello Qt!"); xlsx.write("A2", 12345); xlsx.write("A3", "=44+33"); xlsx.write("A4", true); xlsx.write("A5", "http://qt-project.org"); xlsx.write("A6", QDate(2013, 12, 27)); xlsx.write("A7", QTime(6, 30)); xlsx.saveAs("Book1.xlsx"); } QXlsx::Document xlsx("Book1.xlsx"); qDebug()<<xlsx.read("A1"); qDebug()<<xlsx.read("A2"); qDebug()<<xlsx.read("A3"); qDebug()<<xlsx.read("A4"); qDebug()<<xlsx.read("A5"); qDebug()<<xlsx.read("A6"); qDebug()<<xlsx.read("A7"); for (int row=1; row<10; ++row) { if (QXlsx::Cell *cell=xlsx.cellAt(row, 1)) qDebug()<<cell->value(); } return 0; }
It would be easy to loop over the cell and check the data
-
Thanks for help me.
I use xlsx.
I can write & read in excel file.
I use above exampel.
I cann't find the string in my excel file. ( search command ) -
@mohsen_yadik said in how to find a string in a excel file with qt?:
I cann't find the string in my excel file. ( search command )
How do u try to find it ?
-
I don't know how to do it.
-
@mohsen_yadik
you have xlsx file and want to search string from qt?
I'm sorry but I do not understand what you want. -
- I don't know how to do it.
Which part of it ?
The sample loops over cells.
All that is left is to compare string?Why did you try so far, please show some code
-
Thanks for help me.
with your guide was done.
Thank you -
@mrjj I get the following error when i run this pro QZip: not a zip file!
Any idea whats wrong here ? -
@Beemaneni-Bala-0
Hi
Can other tool open the zip file ? -
@mrjj All i have is only an excel file. I did not understand why and where zip file is needed here ?
-
@Beemaneni-Bala-0
The excel file (XLSX) is actually a zip file.
Do you try to give it an old binary format ?
what is the extension of the file? -
@mrjj Here is the code snipped . I need to just read an excel file here. i am using linux machine here and i can open excel file using libreoffice
void MainWindow::readExcelFile(QString excelSheetFile){ QXlsx::Document xlsx("ExcelSheet.xlsx"); qDebug()<<xlsx.read("A1"); qDebug()<<xlsx.read("A2"); qDebug()<<xlsx.read("A3"); qDebug()<<xlsx.read("A4"); qDebug()<<xlsx.read("A5"); qDebug()<<xlsx.read("A6"); qDebug()<<xlsx.read("A7"); for (int row=1; row<10; ++row) { qDebug()<<"Row No : "<<row << xlsx.cellAt(row, 1); if (QXlsx::Cell *cell=xlsx.cellAt(row, 1)) qDebug()<< "Cell Data: " << cell->value(); } }
-
Hi
and the file is indeed an xlsx and not the old xls `?
The file you give it, excelSheetFile
Else convert it with libreOffice -
@mrjj Thanks a lot for the information. I had renamed the file to xlsx. That was the issue. After converting using libreoffice it works and i can fetch information.