Click here to Skip to main content
15,798,200 members
Articles / Desktop Programming / MFC

Working with Excel in MFC

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
9 Apr 2013CPOL1 min read 26K   2.4K   20   5
Improved Excel class
XLAutomation in MFC

Using the Code

A few coders asked me to share my developed COlezAutomation class which is taken from here, because I developed a bit these classes. So, I was thinking of put up here a small example of how you can use these Excel classes to achieve a chart via OleAutomation, with more than one series. Of course, you can do any other operation with this automation, such as exporting, importing, working with formulas, working with worksheets, and so on. Now I show here a charting operation.

From File->Play Excel you can start a window top most dialog from where you can control an Excel charting (like an external application), with two kinds of charts (pie or column, 3D or not), and from "Randomize" button you can generate several charts series.

The code is pretty simple and self explanatory, CChartFilterDlg has a CXLEzAutomation pointer which is a wrapper over CXLAutomation object. So, after testing whether Excel is properly installed, CXLEzAutomation pointer is doing remotely needed CXLAutomation operation for charting.

Also, I put a small example of how to convert office files (doc/xls/ppt) into pdf. You can do it from File->Conver File To Pdf item. If the conversion is done successfully, you'll get a statusbar message about that.

Enjoy it!


  • 9th April, 2013: Initial version
  • 2nd December, 2015: Source code updated
  • 7th September 2021: Added 'Convert to PDF' feature


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

Written By
Romania Romania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionWorksheet not changed... Pin
Hyun-woo Jang15-Sep-14 0:06
Hyun-woo Jang15-Sep-14 0:06 
AnswerRe: Worksheet not changed... Pin
_Flaviu15-Sep-14 0:53
_Flaviu15-Sep-14 0:53 
AnswerRe: Worksheet not changed... Pin
_Flaviu15-Sep-14 21:44
_Flaviu15-Sep-14 21:44 
AnswerRe: Worksheet not changed... Pin
KimJinWoo29-Nov-15 3:06
KimJinWoo29-Nov-15 3:06 
GeneralRe: Worksheet not changed... Pin
_Flaviu2-Dec-15 2:08
_Flaviu2-Dec-15 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.