C++ and Excel : Need Simple Charting Example (I can populate sheet with Data)

S

stevo

I am using Microsoft Viusal C++ .Net (unmanaged MFC Application)
and Excel 2002.

I have been able to create and Excel worksheet and fill it with data
from my C++ program. However, I can't figure out how to create a
chart.

I can't find enough documentation on CChart to figure out how to
create a chart.

Can someone show me a simply example or point me to the right
literature?

Thanks
Stephen

Below is my code that creates the excel sheet and populates it with
data:

CApplication oExcel;
CWorkbook oBook;
CWorkbooks oBooks;
CWorksheets oSheets;
CWorksheet oSheet;
CRange oRange;
CChart oChart;
COleVariant covOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
oExcel.CreateDispatch("Excel.Application");

oBooks = oExcel.get_Workbooks();
oBook = oBooks.Add(covOptional);
oSheets = oBook.get_Worksheets();
oSheet = oSheets.get_Item(COleVariant((short)1));
oChart = oBook.get_Charts();
oExcel.put_Visible(TRUE);
oExcel.put_UserControl(TRUE);


COleSafeArray saRet;
COleSafeArray saDateTime;
COleSafeArray saPhaseAdjustmentAngles;


DWORD numElements[2];
numElements[0] = NumberOfCallIns;
numElements[1] = NumberOfCallIns;


// Get a range of data.
oRange = oSheet.get_Range(COleVariant("C13"),covOptional);
oRange = oRange.get_Resize(COleVariant((short)NumberOfCallIns),COleVariant((short)24));
saRet.Create(VT_R8,2,numElements);


long index[2];
for (int iRow = 1; iRow < NumberOfCallIns; iRow++) {
for (int iCol = 1; iCol <= 24; iCol++) {
index[0]=iRow-1;
index[1]=iCol-1;
outBug << iRow << "\t" << iCol << endl;


saRet.PutElement(index,&StoreValuesForOutput[iCol][iRow]);
 
S

stevo

I found the following article on MSDN.

How To Use MFC to Create a Microsoft Excel Chart
http://support.microsoft.com/default.aspx?scid=kb;en-us;178783

but is uses #include "excel.h" (for Excel 2002) and I don't have
that .h on my computer (I have full install of VC++ .Net and Excel
2002).

Any Ideas?

Thanks
Stephen




Tom Ogilvy said:
Try searching the knowledge base

http://support.microsoft.com

choose advanced search, then select Visual C++ as product and search on
terms like

Excel Chart

--
Regards,
Tom Ogilvy

stevo said:
I am using Microsoft Viusal C++ .Net (unmanaged MFC Application)
and Excel 2002.

I have been able to create and Excel worksheet and fill it with data
from my C++ program. However, I can't figure out how to create a
chart.

I can't find enough documentation on CChart to figure out how to
create a chart.

Can someone show me a simply example or point me to the right
literature?

Thanks
Stephen

Below is my code that creates the excel sheet and populates it with
data:

CApplication oExcel;
CWorkbook oBook;
CWorkbooks oBooks;
CWorksheets oSheets;
CWorksheet oSheet;
CRange oRange;
CChart oChart;
COleVariant covOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
oExcel.CreateDispatch("Excel.Application");

oBooks = oExcel.get_Workbooks();
oBook = oBooks.Add(covOptional);
oSheets = oBook.get_Worksheets();
oSheet = oSheets.get_Item(COleVariant((short)1));
oChart = oBook.get_Charts();
oExcel.put_Visible(TRUE);
oExcel.put_UserControl(TRUE);


COleSafeArray saRet;
COleSafeArray saDateTime;
COleSafeArray saPhaseAdjustmentAngles;


DWORD numElements[2];
numElements[0] = NumberOfCallIns;
numElements[1] = NumberOfCallIns;


// Get a range of data.
oRange = oSheet.get_Range(COleVariant("C13"),covOptional);
oRange = oRange.get_Resize(COleVariant((short)NumberOfCallIns),COleVariant((short)24)
);
saRet.Create(VT_R8,2,numElements);


long index[2];
for (int iRow = 1; iRow < NumberOfCallIns; iRow++) {
for (int iCol = 1; iCol <= 24; iCol++) {
index[0]=iRow-1;
index[1]=iCol-1;
outBug << iRow << "\t" << iCol << endl;


saRet.PutElement(index,&StoreValuesForOutput[iCol][iRow]);
 
T

Tom Ogilvy

http://support.microsoft.com/default.aspx?scid=kb;en-us;192348&Product=vcc

look at step 9 - it talks about excel.h

does that help?

--
Regards,
Tom Ogilvy


stevo said:
I found the following article on MSDN.

How To Use MFC to Create a Microsoft Excel Chart
http://support.microsoft.com/default.aspx?scid=kb;en-us;178783

but is uses #include "excel.h" (for Excel 2002) and I don't have
that .h on my computer (I have full install of VC++ .Net and Excel
2002).

Any Ideas?

Thanks
Stephen




"Tom Ogilvy" <[email protected]> wrote in message
Try searching the knowledge base

http://support.microsoft.com

choose advanced search, then select Visual C++ as product and search on
terms like

Excel Chart

--
Regards,
Tom Ogilvy

stevo said:
I am using Microsoft Viusal C++ .Net (unmanaged MFC Application)
and Excel 2002.

I have been able to create and Excel worksheet and fill it with data
from my C++ program. However, I can't figure out how to create a
chart.

I can't find enough documentation on CChart to figure out how to
create a chart.

Can someone show me a simply example or point me to the right
literature?

Thanks
Stephen

Below is my code that creates the excel sheet and populates it with
data:

CApplication oExcel;
CWorkbook oBook;
CWorkbooks oBooks;
CWorksheets oSheets;
CWorksheet oSheet;
CRange oRange;
CChart oChart;
COleVariant covOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
oExcel.CreateDispatch("Excel.Application");

oBooks = oExcel.get_Workbooks();
oBook = oBooks.Add(covOptional);
oSheets = oBook.get_Worksheets();
oSheet = oSheets.get_Item(COleVariant((short)1));
oChart = oBook.get_Charts();
oExcel.put_Visible(TRUE);
oExcel.put_UserControl(TRUE);


COleSafeArray saRet;
COleSafeArray saDateTime;
COleSafeArray saPhaseAdjustmentAngles;


DWORD numElements[2];
numElements[0] = NumberOfCallIns;
numElements[1] = NumberOfCallIns;


// Get a range of data.
oRange = oSheet.get_Range(COleVariant("C13"),covOptional);
oRange =
oRange.get_Resize(COleVariant((short)NumberOfCallIns),COleVariant((short)24)
);
saRet.Create(VT_R8,2,numElements);


long index[2];
for (int iRow = 1; iRow < NumberOfCallIns; iRow++) {
for (int iCol = 1; iCol <= 24; iCol++) {
index[0]=iRow-1;
index[1]=iCol-1;
outBug << iRow << "\t" << iCol << endl;


saRet.PutElement(index,&StoreValuesForOutput[iCol][iRow]);
 
S

stevo

Yes, Thanks Tom.








Tom Ogilvy said:
http://support.microsoft.com/default.aspx?scid=kb;en-us;192348&Product=vcc

look at step 9 - it talks about excel.h

does that help?

--
Regards,
Tom Ogilvy


stevo said:
I found the following article on MSDN.

How To Use MFC to Create a Microsoft Excel Chart
http://support.microsoft.com/default.aspx?scid=kb;en-us;178783

but is uses #include "excel.h" (for Excel 2002) and I don't have
that .h on my computer (I have full install of VC++ .Net and Excel
2002).

Any Ideas?

Thanks
Stephen




"Tom Ogilvy" <[email protected]> wrote in message
Try searching the knowledge base

http://support.microsoft.com

choose advanced search, then select Visual C++ as product and search on
terms like

Excel Chart

--
Regards,
Tom Ogilvy

I am using Microsoft Viusal C++ .Net (unmanaged MFC Application)
and Excel 2002.

I have been able to create and Excel worksheet and fill it with data
from my C++ program. However, I can't figure out how to create a
chart.

I can't find enough documentation on CChart to figure out how to
create a chart.

Can someone show me a simply example or point me to the right
literature?

Thanks
Stephen

Below is my code that creates the excel sheet and populates it with
data:

CApplication oExcel;
CWorkbook oBook;
CWorkbooks oBooks;
CWorksheets oSheets;
CWorksheet oSheet;
CRange oRange;
CChart oChart;
COleVariant covOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
oExcel.CreateDispatch("Excel.Application");

oBooks = oExcel.get_Workbooks();
oBook = oBooks.Add(covOptional);
oSheets = oBook.get_Worksheets();
oSheet = oSheets.get_Item(COleVariant((short)1));
oChart = oBook.get_Charts();
oExcel.put_Visible(TRUE);
oExcel.put_UserControl(TRUE);


COleSafeArray saRet;
COleSafeArray saDateTime;
COleSafeArray saPhaseAdjustmentAngles;


DWORD numElements[2];
numElements[0] = NumberOfCallIns;
numElements[1] = NumberOfCallIns;


// Get a range of data.
oRange = oSheet.get_Range(COleVariant("C13"),covOptional);
oRange =
oRange.get_Resize(COleVariant((short)NumberOfCallIns),COleVariant((short)24)
);
saRet.Create(VT_R8,2,numElements);


long index[2];
for (int iRow = 1; iRow < NumberOfCallIns; iRow++) {
for (int iCol = 1; iCol <= 24; iCol++) {
index[0]=iRow-1;
index[1]=iCol-1;
outBug << iRow << "\t" << iCol << endl;


saRet.PutElement(index,&StoreValuesForOutput[iCol][iRow]);
 
Top