setting borders in exel sheet Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
naveen2525
Earned a small fee
Earned a small fee
Posts: 20
Joined: Fri Dec 14, 2012 4:58 am

setting borders in exel sheet

Post by naveen2525 » Thu Feb 07, 2013 9:28 am

hello,
i would like to set allborders to my exel sheet cell through coding please help me

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2465
Joined: Sun Jan 03, 2010 5:45 pm

Re: setting borders in exel sheet

Post by PB » Thu Feb 07, 2013 6:55 pm

Hi,

on the wxWidgets side you have to use wxAutomationObject, see oleauto sample how to use it. On Excel side, you need to either use Range.Borders property or Range.BorderAround() method etc.

You could also give my wxAutoExcel library (currently only SVN version available, requires MSVC 2008 and wxWidgets 2.9.5) a try, this is how you would do it using it (from its minimal sample), much less painfull than using plain automation calls

Code: Select all

    // obtain a rectangular area containing all worksheet cells with values
    range = worksheet.GetUsedRange();    
    // add medium-weight borders on the outside and thin-weight on the inside
    wxExcelBorders borders = range.GetBorders();
    borders[xlEdgeTop].SetWeight(xlMedium);
    borders[xlEdgeLeft].SetWeight(xlMedium);    
    borders[xlEdgeBottom].SetWeight(xlMedium);
    borders[xlEdgeRight].SetWeight(xlMedium);
    borders[xlInsideHorizontal].SetWeight(xlThin);
    borders[xlInsideVertical].SetWeight(xlThin);
    
    // format the totals row
    range = worksheet.GetRange("A4:E4");
    wxExcelFont font = range.GetFont();
    font.SetBold(true);
    font.SetColor(*wxBLUE);
    font.SetSize(font.GetSize() * 1.5);

    // set the cell background to light grey
    range.GetInterior().SetColor(*wxLIGHT_GREY);

    // merge the first four cells
    range.GetRange("A1:D1").Merge();
    
    // get the range for cell with the total sum
    // using another method of specifying a range - row and column
    range = range.GetCells(NULL, WXAEEP(5L)); // wxAEEP is a helper macro for passing pointers to longs and Excel enums
    // add a thick double-lined blue border around the total sum
    range.BorderAround(wxAEEP(xlDouble), WXAEEP(xlThick), NULL, wxBLUE);

Post Reply