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 fast read excel file, with VC2005

How to fast read excel file, with VC2005

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
5 Posts 2 Posters 2 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.
  • L Offline
    L Offline
    lichengbyd
    wrote on last edited by
    #1

    When read big excel file, it takes many time to read cell one by one.

    J 1 Reply Last reply
    0
    • L lichengbyd

      When read big excel file, it takes many time to read cell one by one.

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      You did not tell us which method you are using to read Excel files. If you use OLE automation, you should use arrays to read multiple cells at once (e.g. all cells of a row or all cells of muliple rows). See the MSDN article How to automate Excel from MFC and Visual C++ 2005 or Visual C++ .NET to fill or obtain data in a range using arrays[^].

      L 1 Reply Last reply
      0
      • J Jochen Arndt

        You did not tell us which method you are using to read Excel files. If you use OLE automation, you should use arrays to read multiple cells at once (e.g. all cells of a row or all cells of muliple rows). See the MSDN article How to automate Excel from MFC and Visual C++ 2005 or Visual C++ .NET to fill or obtain data in a range using arrays[^].

        L Offline
        L Offline
        lichengbyd
        wrote on last edited by
        #3

        I'm Using Library for Office // Loop through the data and report the contents. for (int rowCounter = 1; rowCounter <= iRows; rowCounter++) { for (int colCounter = 1; colCounter <= iCols; colCounter++) { index[0]=rowCounter; index[1]=colCounter; COleVariant vData; saRet.GetElement(index,vData); CString szdata(vData); valueString += szdata; valueString += "\t"; } valueString += "\r\n"; } In this example, it's using loop to read cells, the reading speed is not good.

        J 1 Reply Last reply
        0
        • L lichengbyd

          I'm Using Library for Office // Loop through the data and report the contents. for (int rowCounter = 1; rowCounter <= iRows; rowCounter++) { for (int colCounter = 1; colCounter <= iCols; colCounter++) { index[0]=rowCounter; index[1]=colCounter; COleVariant vData; saRet.GetElement(index,vData); CString szdata(vData); valueString += szdata; valueString += "\t"; } valueString += "\r\n"; } In this example, it's using loop to read cells, the reading speed is not good.

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          Which library?

          lichengbyd wrote:

          In this example, it's using loop to read cells, the reading speed is not good.

          It is using the loops to extract the values from the safe array. But the data are already in memory of your application. You missed the call that retrieves the data from Excel:

          // Get the data.
          COleSafeArray saRet(oRange.get_Value(covOptional));

          L 1 Reply Last reply
          0
          • J Jochen Arndt

            Which library?

            lichengbyd wrote:

            In this example, it's using loop to read cells, the reading speed is not good.

            It is using the loops to extract the values from the safe array. But the data are already in memory of your application. You missed the call that retrieves the data from Excel:

            // Get the data.
            COleSafeArray saRet(oRange.get_Value(covOptional));

            L Offline
            L Offline
            lichengbyd
            wrote on last edited by
            #5

            Indeed, thanks for you infomation!

            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