change font style and colors in excel spreadsheet?
-
:confused::confused:Hi, I want to change the font style i.e. headers with bold and change some colors in the data tables (columns or rows) depending on the value. I dont know whether this can be done or not. Please guide me as i have not used excel before. I have to use MFC and i have excel 2003. Looking forward to a response. Thanks a lot in advance. Regards, Himanshu
-
:confused::confused:Hi, I want to change the font style i.e. headers with bold and change some colors in the data tables (columns or rows) depending on the value. I dont know whether this can be done or not. Please guide me as i have not used excel before. I have to use MFC and i have excel 2003. Looking forward to a response. Thanks a lot in advance. Regards, Himanshu
A Snippet of code from a junk app of mine :-
//Start a new workbook in Excel
_Application oApp;
oApp.CreateDispatch("Excel.Application");
if (!oApp)
{
AfxMessageBox("Cannot start Excel");
return;
}Workbooks oBooks = oApp.GetWorkbooks();
_Workbook oBook = oBooks.Add(vOpt);
Worksheets oSheets = oBook.GetWorksheets();
_Worksheet oSheet = oSheets.GetItem(COleVariant((short)1));
Range oRange;
long bMergeAcross = 0;
//prepare style
Styles styles = oBook.GetStyles();Style s = styles.Add("Style with Center Text", vOpt);
s.SetVerticalAlignment(2);
s.SetHorizontalAlignment(3);
Font oFont = s.GetFont();
oFont.SetSize(COleVariant((long)FONT_SIZE_JUSTIFICATION));VARIANT vt;
vt.vt = VT_DISPATCH;
vt.pdispVal = s.m_lpDispatch;//use vt as a new style
oRange.SetStyle(vt);oRange=oSheet.GetRange(COleVariant("A1"),COleVariant("A2"));
oFont = oRange.GetFont();
oFont.SetBold(COleVariant((short)TRUE));Hope this helps :) By the way you will have to import the type library to use these classes For more help Click it[^] C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg