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. Export data to excel

Export data to excel

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
2 Posts 2 Posters 0 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.
  • G Offline
    G Offline
    Gerald Mercet
    wrote on last edited by
    #1

    Hi everybody, I would like to export data from a safearray to range in excel. So, ii've read the articles Q186120 which gives an explantion and an example to do it. I've tried to test it in my application, first i ve done simply in trying to put in a specific set of range the figure "1". But when i test it it doesn't work the only first cell ("A1") is filled by "1", WHY??? So, you could find the code i've wrote, so, if someone could help me! Thanks in advance . . . . _Application FracApp; _Workbook FracBook; _Worksheet FracSheet; Workbooks FracBooks; Worksheets FracSheets; Range FracRange; LPDISPATCH lpDisp; COleVariant Optional((long)DISP_E_PARAMNOTFOUND,VT_ERROR); COleSafeArray FracArray; DWORD NumOfElements[2]; int NumberOfRows,NumberOfCols; //pour le "SAFEARRAY" long FracIndex[2]; long lRow,lCol; double Temporary; if(!FracApp.CreateDispatch("Excel.Application")) { AfxMessageBox("Pb avec CreateDispatch sur Excel"); return; } lpDisp=FracApp.GetWorkbooks(); ASSERT(lpDisp); FracBooks.AttachDispatch(lpDisp); lpDisp=FracBooks.Open("D:\\FractaLab\\Fractal_v1_0\\Test.xls",Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional); ASSERT(lpDisp); FracBook.AttachDispatch(lpDisp); lpDisp=FracBook.GetWorksheets(); ASSERT(lpDisp); FracSheets.AttachDispatch(lpDisp); lpDisp=FracSheets.GetItem(COleVariant((short)1)); ASSERT(lpDisp); FracSheet.AttachDispatch(lpDisp); lpDisp=FracSheet.GetRange(COleVariant("A1"),COleVariant("A1")); ASSERT(lpDisp); FracRange.AttachDispatch(lpDisp); NumberOfRows=m_dlgNumHisto+1-m_dlgNumSample; NumberOfCols=256; FracRange.GetResize(COleVariant((short)(NumberOfRows)),COleVariant((short)(NumberOfCols))); FracApp.SetVisible(TRUE); FracRange.Clear(); //Création du tab de type SAFEARRAY. NumOfElements[0]=NumberOfRows; NumOfElements[1]=NumberOfCols; FracArray.Create(VT_R8,2,NumOfElements); //Remplissage du SAFEARRAY for(lCol=0;lCol

    K 1 Reply Last reply
    0
    • G Gerald Mercet

      Hi everybody, I would like to export data from a safearray to range in excel. So, ii've read the articles Q186120 which gives an explantion and an example to do it. I've tried to test it in my application, first i ve done simply in trying to put in a specific set of range the figure "1". But when i test it it doesn't work the only first cell ("A1") is filled by "1", WHY??? So, you could find the code i've wrote, so, if someone could help me! Thanks in advance . . . . _Application FracApp; _Workbook FracBook; _Worksheet FracSheet; Workbooks FracBooks; Worksheets FracSheets; Range FracRange; LPDISPATCH lpDisp; COleVariant Optional((long)DISP_E_PARAMNOTFOUND,VT_ERROR); COleSafeArray FracArray; DWORD NumOfElements[2]; int NumberOfRows,NumberOfCols; //pour le "SAFEARRAY" long FracIndex[2]; long lRow,lCol; double Temporary; if(!FracApp.CreateDispatch("Excel.Application")) { AfxMessageBox("Pb avec CreateDispatch sur Excel"); return; } lpDisp=FracApp.GetWorkbooks(); ASSERT(lpDisp); FracBooks.AttachDispatch(lpDisp); lpDisp=FracBooks.Open("D:\\FractaLab\\Fractal_v1_0\\Test.xls",Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional,Optional); ASSERT(lpDisp); FracBook.AttachDispatch(lpDisp); lpDisp=FracBook.GetWorksheets(); ASSERT(lpDisp); FracSheets.AttachDispatch(lpDisp); lpDisp=FracSheets.GetItem(COleVariant((short)1)); ASSERT(lpDisp); FracSheet.AttachDispatch(lpDisp); lpDisp=FracSheet.GetRange(COleVariant("A1"),COleVariant("A1")); ASSERT(lpDisp); FracRange.AttachDispatch(lpDisp); NumberOfRows=m_dlgNumHisto+1-m_dlgNumSample; NumberOfCols=256; FracRange.GetResize(COleVariant((short)(NumberOfRows)),COleVariant((short)(NumberOfCols))); FracApp.SetVisible(TRUE); FracRange.Clear(); //Création du tab de type SAFEARRAY. NumOfElements[0]=NumberOfRows; NumOfElements[1]=NumberOfCols; FracArray.Create(VT_R8,2,NumOfElements); //Remplissage du SAFEARRAY for(lCol=0;lCol

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      I think your only settings the first value. Maybe the approch with the array is not the easiest way. If done this (where is the code???) with writing to a cell and the changing the position, it worked well. Tip: if you write in a csv (comma separated file) with ";" as delimiter excel can open it easily. If you need you can also deploy a excel macro to some strange things. If also read in CP an article about writing to Excel via ODBC Functions, it is working.

      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