Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. change font style and colors in excel spreadsheet?

change font style and colors in excel spreadsheet?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xxhimanshu
    wrote on last edited by
    #1

    :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

    M 1 Reply Last reply
    0
    • X xxhimanshu

      :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

      M Offline
      M Offline
      Monty2
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups