Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Getting FontStyle from Excel Cell programtically in C++

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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…

610 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