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 {
for(lRow=0;lRow {
FracIndex[0]=lRow;
FracIndex[1]=lCol; Temporary=(double)1;
FracArray.PutElement(FracIndex,&Temporary);
}
}
FracRange.SetValue(COleVariant(FracArray));
FracArray.Detach();
FracApp.SetUserControl(TRUE);
.
.
.
jayjay
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 {
for(lRow=0;lRow {
FracIndex[0]=lRow;
FracIndex[1]=lCol; Temporary=(double)1;
FracArray.PutElement(FracIndex,&Temporary);
}
}
FracRange.SetValue(COleVariant(FracArray));
FracArray.Detach();
FracApp.SetUserControl(TRUE);
.
.
.
jayjay