Solved

Getting FontStyle from Excel Cell programtically in C++

Posted on 2010-11-23
1
682 Views
Last Modified: 2013-12-03
I am doing excel automation using C++. I have also embedded the excel window in my own window.

Before displaying the Excel i have changed the fontStyle of each cell  using

m_pXlFont = m_pXlRange->Font;

m_pXlFont->Name = _T("Arial");

m_pXlFont->FontStyle = _T("Bold Italic");

Excel takes this font and displays the data.

Now i go in excel that change text in few cells and also change the fontStyle.

After that i want to retrieve the new fontstyle and text like this...

 

Excel::_WorksheetPtr pSheet = m_pXlApp->ActiveSheet;

Excel::RangePtr pRange = pSheet->Cells;

Excel::RangePtr pBeginRange;

Excel::FontPtr
pXlFont;

std::ofstream myfile ("c:\\example.txt");

 

for (long r = 1; r < numRowsData; r++)

{

for (short c = 1 ; c < numColsData; c++) {

pBeginRange = pRange->Item[r][c];

pXlFont = pBeginRange->Font;

_variant_t bfont = m_pXlFont->FontStyle;

_bstr_t b =bfont;

TCHAR* lpszText2 = _com_util::ConvertBSTRToString(b);

_bstr_t cellValue = pRange->Item[r][c];

TCHAR* lpszText4 = _com_util::ConvertBSTRToString(cellValue);

myfile << r << " " << c << " " << lpszText3 << " " << lpszText4 << std::endl;

 

}

}

myfile.close();

I get the changed text but i do not the changed fontstyle. The FonstStyle is same as before...i.e. what i had set programatically.

what wrong i am doing here?

 
0
Comment
Question by:sramya
1 Comment
 
LVL 9

Accepted Solution

by:
expert_tanmay earned 500 total points
ID: 34325584
You have made a mistake here

pXlFont = pBeginRange->Font;

_variant_t bfont = m_pXlFont->FontStyle;

correct it to read

pXlFont = pBeginRange->Font;

_variant_t bfont = pXlFont->FontStyle;


Cheers
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now