Solved

Getting FontStyle from Excel Cell programtically in C++

Posted on 2010-11-23
1
689 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
zeroFront challenge 7 124
JQuery serialize and unserialize 8 201
Need a complete list of ASP.NET page load events 3 64
Increment column based of a FK 8 53
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

726 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