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 Offline
    M Offline
    mohsen_yadik
    wrote on 9 Aug 2017, 10:36 last edited by
    #1

    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.

    R 1 Reply Last reply 9 Aug 2017, 10:52
    0
    • M mohsen_yadik
      9 Aug 2017, 10:36

      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.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 9 Aug 2017, 10:52 last edited by raven-worx 8 Sept 2017, 11:02
      #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
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 9 Aug 2017, 10:58 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 14 Sept 2020, 13:33
        3
        • M Offline
          M Offline
          mohsen_yadik
          wrote on 9 Aug 2017, 11:12 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 )

          M 1 Reply Last reply 9 Aug 2017, 11:16
          0
          • M mohsen_yadik
            9 Aug 2017, 11:12

            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 )

            M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 9 Aug 2017, 11:16 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 9 Aug 2017, 11:29
            0
            • M mrjj
              9 Aug 2017, 11:16

              @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 9 Aug 2017, 11:29 last edited by
              #6

              I don't know how to do it.

              T M 2 Replies Last reply 9 Aug 2017, 11:42
              0
              • M mohsen_yadik
                9 Aug 2017, 11:29

                I don't know how to do it.

                T Offline
                T Offline
                Taz742
                wrote on 9 Aug 2017, 11:42 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
                  9 Aug 2017, 11:29

                  I don't know how to do it.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 9 Aug 2017, 11:45 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 9 Aug 2017, 12:14
                  1
                  • M mrjj
                    9 Aug 2017, 11:45

                    @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 9 Aug 2017, 12:14 last edited by
                    #9

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

                    1 Reply Last reply
                    1
                    • M mrjj
                      9 Aug 2017, 10:58

                      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 14 Sept 2020, 13:33 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 ?

                      M 1 Reply Last reply 14 Sept 2020, 13:53
                      0
                      • B Beemaneni Bala 0
                        14 Sept 2020, 13:33

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

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 14 Sept 2020, 13:53 last edited by
                        #11

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

                        B 2 Replies Last reply 14 Sept 2020, 14:33
                        0
                        • M mrjj
                          14 Sept 2020, 13:53

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

                          B Offline
                          B Offline
                          Beemaneni Bala 0
                          wrote on 14 Sept 2020, 14:33 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 ?

                          M 1 Reply Last reply 14 Sept 2020, 14:43
                          0
                          • B Beemaneni Bala 0
                            14 Sept 2020, 14:33

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

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 14 Sept 2020, 14:43 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
                            • M mrjj
                              14 Sept 2020, 13:53

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

                              B Offline
                              B Offline
                              Beemaneni Bala 0
                              wrote on 14 Sept 2020, 14:46 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();
                                  }
                              }
                              
                              
                              M 1 Reply Last reply 14 Sept 2020, 14:47
                              0
                              • B Beemaneni Bala 0
                                14 Sept 2020, 14:46

                                @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();
                                    }
                                }
                                
                                
                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 14 Sept 2020, 14:47 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 14 Sept 2020, 14:56
                                1
                                • M mrjj
                                  14 Sept 2020, 14:47

                                  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 14 Sept 2020, 14:56 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