Hi
I include here some code I use to read Excel file
Use the Visual C++ on-line Help for details
HTH
Thierry
EMail: Thierry.Marneffe@swing.be
WebSite:
Here it is:
COleVariant covOptional(( long) DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant covTrue(( short) TRUE);
COleVariant covFalse(( short) FALSE);
try
{
_Application app;
_Workbook book;
_Worksheet sheet;
Workbooks books;
Worksheets sheets;
Range range;
if ( !app.CreateDispatch( "Excel.Application"

)
{
AfxMessageBox( Unable to Start Excel !!!"

;
return;
}
CWaitCursor wait;
// Get Workbooks Collection
books = app.GetWorkbooks();
// Open File
CString stre;
book = books.Open( strFile, covOptional, covTrue, covOptional, covOptional,
covOptional, covTrue, covOptional, covOptional, covFalse,
covOptional, covOptional, covFalse);
// Get Sheets
sheets = book.GetSheets();
// Get First Sheet
sheet = sheets.GetItem( COleVariant(( short) 1));
// Scan File to Get some Data
CMsg msg;
COleVariant covCell;
COleVariant covValue;
CTime t;
CString strUnit;
int nBatchNbr;
char szBuffer[100];
THIS is A SAMPLE ... DO as you NEED ...
for ( int nRow = 9; nRow <= 90; nRow += 2)
{
// Get Date
covCell = Cell( nRow, 3);
range = sheet.GetRange( covCell, covCell);
covValue = range.GetValue();
// Extract Date from COleVariant
if ( covValue.vt == VT_DATE)
{
t = GetOleVariant( covValue, t);
}
else
{
CString strMsg;
strMsg.Format( "Error Getting Time Data (Row %d Col 3) !!!", nRow);
AfxMessageBox( strMsg);
// Avoid 'Save Changes' message
book.SetSaved( TRUE);
// Quit Excel
app.Quit();
}
// Scan Other Data
for ( int nCol = 4; nCol <= 27; nCol++)
{
// Get Unit Name
covCell = Cell( nRow, nCol);
range = sheet.GetRange( covCell, covCell);
covValue.Clear();
covValue = range.GetValue();
// Extract String ( with safety check)
if ( covValue.vt == VT_BSTR)
{
// Extract String
// Note: BSTRs are wide, double-byte (Unicode) strings on
// 32-bit Windows platforms
unsigned cmb = wcstombs( NULL, covValue.bstrVal,
SysStringLen( covValue.bstrVal)) + 1;
strnset( szBuffer, 100, ' ');
wcstombs( szBuffer, covValue.bstrVal, cmb);
strUnit.Format( "%s", szBuffer);
}
}
}
// Avoid 'Save Changes' message
book.SetSaved( TRUE);
// Quit Excel
app.Quit();
}
catch( COleException *e)
{
char szBuffer[1024];
sprintf( szBuffer, "COleException. SCODE: %08lx.", (long)e->m_sc);
m_EventLog.WriteLine( szBuffer);
}
catch( COleDispatchException *e)
{
char szBuffer[1024];
sprintf( szBuffer,
"COleDispatchException. SCODE: %08lx, Description: \"%s\".",
( long) e->m_wCode, ( LPSTR) e->m_strDescription.GetBuffer(1024));
m_EventLog.WriteLine( szBuffer);
}
catch(...)
{
m_EventLog.WriteLine( "General Exception caught ..."

;
}
}