Click here to Skip to main content
15,879,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,

I have use this link for reference.

Automating Excel 2007 and creating charts using C++ MFC application in Visual Studio 2008[^]


But in this project excel cell values are hard coded by using range.put_value2

range = sheet.get_Range(COleVariant(TEXT("C3")),COleVariant(TEXT("C3")));
range.put_Value2(COleVariant(short(30)));

I want to plot graph for excel files. whichever file I choose It should plot the graph for that excel file data. I don't want to hardcode the data How i can do it?

Thank you.
Posted
Comments
George Jonsson 3-Jul-14 22:45pm    
Do you want to read existing data from an Excel document and then make the graph pro grammatically in the same Excel document?
One way to make it easier is to use named columns and the get the columns via SQL command.
The problem is I have never connected to an Excel sheet via OleDb or ODBC in C++, only in C#.
http://msdn.microsoft.com/en-us/library/7wtdsdkh.aspx

1 solution

Create instances of the COleVariant with your values an apply them in the code

CString myCell = TEXT("C3");//or any other
range = sheet.get_Range(COleVariant(myCell),COleVariant(myCell));
 
Share this answer
 
Comments
peoria123 7-Jul-14 13:51pm    
Hi,
Thank you for your answer. It is working but I have very big excel file with lots of rows and 4 columns. Row size is not fixed .can I read whole coloumn at once insted of reading cell by cell. or can it be possible to open excel file in Sheet1 and it will plot graph for the data which is in sheet 1.

Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900