Solved

Getting FontStyle from Excel Cell programtically in C++

Posted on 2010-11-23
1
683 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA "SendKeys" Syntax for Multiple Keystrokes 7 103
Tab order 16 63
dialer.exe 4 58
Entity Framework Code first - Specify minimum one cardinality in a many to many relation 10 57
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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…

867 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

20 Experts available now in Live!

Get 1:1 Help Now