Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to read .Doc, pdf, .xls etc file?

How to read .Doc, pdf, .xls etc file?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++helpquestion
8 Posts 7 Posters 1 Views 1 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.
  • A Offline
    A Offline
    Amarelia
    wrote on last edited by
    #1

    HI, I need to read .doc,.xls,.pdf etc... file and then encrypt/decrypt the same but I am not able to read the file properly using CFile object. How to read these files? what are the functions to read the same? Any example if possible. I am not using Doc/View architecure. I am developing MFC Dialog based application. Your help and time is much appreciated. Thanks & Best Regards, Mahesh

    T D G B F 5 Replies Last reply
    0
    • A Amarelia

      HI, I need to read .doc,.xls,.pdf etc... file and then encrypt/decrypt the same but I am not able to read the file properly using CFile object. How to read these files? what are the functions to read the same? Any example if possible. I am not using Doc/View architecure. I am developing MFC Dialog based application. Your help and time is much appreciated. Thanks & Best Regards, Mahesh

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      they are not text files, they are binary files, so, if you use fscanf(), cin or such basic functions, you'll get "strange" data. search for any api provided with Office...


      TOXCCT >>> GEII power
      [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

      1 Reply Last reply
      0
      • A Amarelia

        HI, I need to read .doc,.xls,.pdf etc... file and then encrypt/decrypt the same but I am not able to read the file properly using CFile object. How to read these files? what are the functions to read the same? Any example if possible. I am not using Doc/View architecure. I am developing MFC Dialog based application. Your help and time is much appreciated. Thanks & Best Regards, Mahesh

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Amarelia wrote:

        ...but I am not able to read the file properly using CFile object.

        Why not?


        "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

        A 1 Reply Last reply
        0
        • A Amarelia

          HI, I need to read .doc,.xls,.pdf etc... file and then encrypt/decrypt the same but I am not able to read the file properly using CFile object. How to read these files? what are the functions to read the same? Any example if possible. I am not using Doc/View architecure. I am developing MFC Dialog based application. Your help and time is much appreciated. Thanks & Best Regards, Mahesh

          G Offline
          G Offline
          grigsoft
          wrote on last edited by
          #4

          You can get text from MS Office files by using COM, but this requires office installed. Next, on new systems you can check IFilter interface - system uses it to index office files. Finaly, you can use third party libraries. I can recommend http://www.wordcnv.com[^] - their libraries are very fast and support is the simply the best I have seen. Igor Green http://www.grigsoft.com/ - files and folders comparison tools

          1 Reply Last reply
          0
          • A Amarelia

            HI, I need to read .doc,.xls,.pdf etc... file and then encrypt/decrypt the same but I am not able to read the file properly using CFile object. How to read these files? what are the functions to read the same? Any example if possible. I am not using Doc/View architecure. I am developing MFC Dialog based application. Your help and time is much appreciated. Thanks & Best Regards, Mahesh

            B Offline
            B Offline
            Bob Flynn
            wrote on last edited by
            #5

            Try here Office Automation Using Visual C++[^]

            1 Reply Last reply
            0
            • A Amarelia

              HI, I need to read .doc,.xls,.pdf etc... file and then encrypt/decrypt the same but I am not able to read the file properly using CFile object. How to read these files? what are the functions to read the same? Any example if possible. I am not using Doc/View architecure. I am developing MFC Dialog based application. Your help and time is much appreciated. Thanks & Best Regards, Mahesh

              F Offline
              F Offline
              FarPointer
              wrote on last edited by
              #6

              Hi, i guess you need to go through automation please see any standard MFC book and you can sail through easily,reading of excelfile is most time consuming if they have large data ,if posible convert them to CSV ( if you can ) and then parse them as you do on a text file . actually you can convert all the above formats to text format and parse ,for that you need to CreateDispatch on the respective application object and ask them to save the coressponding data in text formats . Regards, FarPointer

              1 Reply Last reply
              0
              • D David Crow

                Amarelia wrote:

                ...but I am not able to read the file properly using CFile object.

                Why not?


                "The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb

                A Offline
                A Offline
                Amarelia
                wrote on last edited by
                #7

                Hi, Thanks for the reply, I do it the following way... CStdioFile fileToRead; char * StringBlock = new char[64000]; fileToRead.Open(sCurrPath, CFile::modeRead | CFile::typeBinary, &feError); nBytesRead = fileToRead.Read((unsigned short *)StringBlock, 60000); The value of nBytesRead = 60000 after the last statement executes, but the StringBlock contains only few junk characters only. May be it encounters NULL or something like that which truncates it to only few chars. According to this the function reads the file correctly but the problem is in storing the data. I want to read maximum data possible at one go for the sake of my app's speed . Please give appropriate solution. Best regards and Thanks, Mahesh

                K 1 Reply Last reply
                0
                • A Amarelia

                  Hi, Thanks for the reply, I do it the following way... CStdioFile fileToRead; char * StringBlock = new char[64000]; fileToRead.Open(sCurrPath, CFile::modeRead | CFile::typeBinary, &feError); nBytesRead = fileToRead.Read((unsigned short *)StringBlock, 60000); The value of nBytesRead = 60000 after the last statement executes, but the StringBlock contains only few junk characters only. May be it encounters NULL or something like that which truncates it to only few chars. According to this the function reads the file correctly but the problem is in storing the data. I want to read maximum data possible at one go for the sake of my app's speed . Please give appropriate solution. Best regards and Thanks, Mahesh

                  K Offline
                  K Offline
                  kakan
                  wrote on last edited by
                  #8

                  If the Read() tells you that it did read 60000 bytes, then that's the truth. Your current problem is to display those bytes. Since most word processing files (all of them) contains a lot of binary information, your buffer is bound to have a lot of '\0'-chars. Just trust nBytesRead.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups