i want to copy excel data in my Cstring Array ..i trying this code
CString strpath;
m_wndCtrl.GetWindowTextW(strpath); LPCTSTR str=(LPCTSTR)strpath;
CApplication app; CWorkbook book;
CWorksheet sheet;
CWorkbooks books;
CWorksheets sheets;
CRange range;
char buf[1024];
VARIANT ret;
LPDISPATCH lpDisp; long count; int i;
COleVariant
covTrue((short)TRUE),
covFalse((short)FALSE),
covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
if(!app.CreateDispatch(_T("Excel.Application")))
{
return;
}
lpDisp = app.get_Workbooks();
ASSERT(lpDisp); books.AttachDispatch( lpDisp );
lpDisp = books.Open(str,
covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional, covOptional, covOptional,
covOptional, covOptional); ASSERT(lpDisp);
book.AttachDispatch( lpDisp );
lpDisp = book.get_Sheets();
ASSERT(lpDisp);
sheets.AttachDispatch(lpDisp);
count = sheets.get_Count();
sprintf(buf, "%ld worksheets in this Workbook.", count);
sheet = sheets.get_Item(COleVariant((short)1));
range = sheet.get_Range(COleVariant(TEXT("A1")),COleVariant(TEXT("B1")));
CString as[100][100];
ret = range.get_Value(covOptional);
COleSafeArray sa(ret);
long lNumRows;
long lNumCols;
sa.GetUBound(1, &lNumRows);
sa.GetUBound(2, &lNumCols);
for(i=0; i<lNumRows; i++)
{
for(int j=0; j<lNumCols; j++)
{
as[i][j]=range.get_Cells[i][j];
}
}
CString crt;
crt.Format(_T("%d"),i); AfxMessageBox(crt+_T("File Successfully Added"));
book.Close(COleVariant((short)FALSE), covOptional, covOptional);
app.Quit();
pls help me
thank you