Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to find a string in a excel file with qt?
Forum Updated to NodeBB v4.3 + New Features

how to find a string in a excel file with qt?

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 5 Posters 3.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mohsen_yadik

    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-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by raven-worx
    #2

    @mohsen_yadik
    old (xls) or new (xlsx) format?

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #3

      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

      B 1 Reply Last reply
      3
      • M Offline
        M Offline
        mohsen_yadik
        wrote on last edited by
        #4

        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 )

        mrjjM 1 Reply Last reply
        0
        • M mohsen_yadik

          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 )

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @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 ?

          M 1 Reply Last reply
          0
          • mrjjM mrjj

            @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 ?

            M Offline
            M Offline
            mohsen_yadik
            wrote on last edited by
            #6

            I don't know how to do it.

            Taz742T mrjjM 2 Replies Last reply
            0
            • M mohsen_yadik

              I don't know how to do it.

              Taz742T Offline
              Taz742T Offline
              Taz742
              wrote on last edited by
              #7

              @mohsen_yadik
              you have xlsx file and want to search string from qt?
              I'm sorry but I do not understand what you want.

              Do what you want.

              1 Reply Last reply
              0
              • M mohsen_yadik

                I don't know how to do it.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @mohsen_yadik

                • 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

                M 1 Reply Last reply
                1
                • mrjjM mrjj

                  @mohsen_yadik

                  • 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

                  M Offline
                  M Offline
                  mohsen_yadik
                  wrote on last edited by
                  #9

                  Thanks for help me.
                  with your guide was done.
                  Thank you

                  1 Reply Last reply
                  1
                  • mrjjM mrjj

                    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

                    B Offline
                    B Offline
                    Beemaneni Bala 0
                    wrote on last edited by
                    #10

                    @mrjj I get the following error when i run this pro QZip: not a zip file!
                    Any idea whats wrong here ?

                    mrjjM 1 Reply Last reply
                    0
                    • B Beemaneni Bala 0

                      @mrjj I get the following error when i run this pro QZip: not a zip file!
                      Any idea whats wrong here ?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @Beemaneni-Bala-0
                      Hi
                      Can other tool open the zip file ?

                      B 2 Replies Last reply
                      0
                      • mrjjM mrjj

                        @Beemaneni-Bala-0
                        Hi
                        Can other tool open the zip file ?

                        B Offline
                        B Offline
                        Beemaneni Bala 0
                        wrote on last edited by
                        #12

                        @mrjj All i have is only an excel file. I did not understand why and where zip file is needed here ?

                        mrjjM 1 Reply Last reply
                        0
                        • B Beemaneni Bala 0

                          @mrjj All i have is only an excel file. I did not understand why and where zip file is needed here ?

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          @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?

                          1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @Beemaneni-Bala-0
                            Hi
                            Can other tool open the zip file ?

                            B Offline
                            B Offline
                            Beemaneni Bala 0
                            wrote on last edited by
                            #14

                            @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();
                                }
                            }
                            
                            
                            mrjjM 1 Reply Last reply
                            0
                            • B Beemaneni Bala 0

                              @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();
                                  }
                              }
                              
                              
                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              Hi
                              and the file is indeed an xlsx and not the old xls `?
                              The file you give it, excelSheetFile
                              Else convert it with libreOffice

                              B 1 Reply Last reply
                              1
                              • mrjjM mrjj

                                Hi
                                and the file is indeed an xlsx and not the old xls `?
                                The file you give it, excelSheetFile
                                Else convert it with libreOffice

                                B Offline
                                B Offline
                                Beemaneni Bala 0
                                wrote on last edited by
                                #16

                                @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.

                                1 Reply Last reply
                                1

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt Extensions
                                • Unsolved