How to fast read excel file, with VC2005
-
When read big excel file, it takes many time to read cell one by one.
-
When read big excel file, it takes many time to read cell one by one.
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[^].
-
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[^].
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.
-
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.
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)); -
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));Indeed, thanks for you infomation!