pravalika reddy

pravalika reddy

  • NA
  • 15
  • 18.5k

how to create and open and save excel sheet in vc++

Feb 9 2015 12:34 AM
please send me procedure of excel creation in vc++

this is my vc++ code 
please help me 
CString strFilename,stFileName;
//Excel _Application;
COleVariant
    covTrue((short)TRUE),
    covFalse((short)FALSE),
    covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
  
SYSTEMTIME sSystemTime;
GetSystemTime(&sSystemTime);
GetLocalTime(&sSystemTime);

stFileName.Format(_T("E:\\TEST%0.2d%0.2d%.4d%0.2d%0.2d%0.2d.xlsx"),sSystemTime.wDay,sSystemTime.wMonth,sSystemTime.wYear,sSystemTime.wHour,sSystemTime.wMinute,sSystemTime.wSecond);
theApp.stFileCreatedTime.Format(_T("%0.2d%0.2d%0.2d"),sSystemTime.wHour,sSystemTime.wMinute,sSystemTime.wSecond);
strFilename = _T("E:\\TEST.xlsx");
theApp.oBooks.Close();
theApp.app.Quit();
theApp.app= NULL;

//bExcelStartFlag = 1;
theApp.strAutoTestFilename = stFileName;

theApp.app.ReleaseDispatch();
// Start Excel and get Application object...
if(!theApp.app.CreateDispatch(_T("Excel.Application")))
{
  AfxMessageBox(_T("Couldn't start Excel."));
}
else
{
//Make Excel Visible and display a message
//Get the Workbooks collection.
theApp.oBooks = theApp.app.GetWorkbooks();
// Excel 2003 takes 15 arguments 
theApp.oBook = theApp.oBooks.Open(strFilename, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional, covOptional);  
 
theApp.oBook.SaveAs(COleVariant(stFileName),covOptional,covOptional,covOptional,covOptional,covOptional,0,covOptional,covOptional,covOptional,covOptional,covOptional); 
             
  }


Answers (1)