?
Solved

Getting FontStyle from Excel Cell programtically in C++

Posted on 2010-11-23
1
Medium Priority
?
693 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 2000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
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…

770 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