Problem with format a single excel column with OLE automation using Delphi

Posted by Snackmoore on Stack Overflow See other posts from Stack Overflow or by Snackmoore
Published on 2010-05-18T10:13:23Z Indexed on 2010/05/20 1:00 UTC
Read the original article Hit count: 396

Filed under:
|
|
|

Dear All,

I have piece of code which I use to format a range of cells in Excel. It works fine in Excel 2007 but when the range is only 1 column wide and it is Excel 2003 instead of 2007, I'll get an error saying the I am assigning invalid value for a border's line style.

** valuables such as "xlInsideHorizontal", I have declared them as CONSTANT with the proper values.

Please help.

   procedure formatCells(FRCELLROW, FRCELLCOL, TOCELLROW, TOCELLCOL: Integer;
                         TOPSTYLE, TOPCOLOUR, TOPWEIGHT,
                         BOTTOMSTYLE, BOTTOMCOLOUR, BOTTOMWEIGHT,
                         LEFTSTYLE, LEFTCOLOUR, LEFTWEIGHT,
                         RIGHTSTYLE, RIGHTCOLOUR, RIGHTWEIGHT: Integer;
                         INNERVSTYLE, INNERVCOLOUR, INNERVWEIGHT: Integer;
                         INNERHSTYLE, INNERHCOLOUR, INNERHWEIGHT: Integer;
                         HORIZONTALCELLALIGNMENT: Integer;
                         FontBold: Boolean;
                         NumberFormat: String
                         );
   var
      tmpRange: Variant;
   begin
        tmpRange := eclApp.range[eclApp.Cells[FRCELLROW, FRCELLCOL],
                                 eclApp.Cells[TOCELLROW, TOCELLCOL]];

        tmpRange.Borders[xlEdgeTop].LineStyle := TOPSTYLE;
        if TOPSTYLE <> xlNone then begin
           tmpRange.Borders[xlEdgeTop].ColorIndex := TOPCOLOUR;
           tmpRange.Borders[xlEdgeTop].Weight := TOPWEIGHT;
        end; //if
        tmpRange.Borders[xlEdgeBottom].LineStyle := BOTTOMSTYLE;
        if BOTTOMSTYLE <> xlNone then begin
           tmpRange.Borders[xlEdgeBottom].ColorIndex := BOTTOMCOLOUR;
           tmpRange.Borders[xlEdgeBottom].Weight := BOTTOMWEIGHT;
        end; //if
        tmpRange.Borders[xlEdgeLeft].LineStyle := LEFTSTYLE;
        if LEFTSTYLE <> xlNone then begin
           tmpRange.Borders[xlEdgeLeft].ColorIndex := LEFTCOLOUR;
           tmpRange.Borders[xlEdgeLeft].Weight := LEFTWEIGHT;
        end; //if
        tmpRange.Borders[xlEdgeRight].LineStyle := RIGHTSTYLE;
        if RIGHTSTYLE <> xlNone then begin
           tmpRange.Borders[xlEdgeRight].ColorIndex := RIGHTCOLOUR;
           tmpRange.Borders[xlEdgeRight].Weight := RIGHTWEIGHT;
        end; //if
        tmpRange.Borders[xlInsideVertical].LineStyle := INNERVSTYLE;
        if INNERVSTYLE <> xlNone then begin
           tmpRange.Borders[xlInsideVertical].ColorIndex := INNERVCOLOUR;
           tmpRange.Borders[xlInsideVertical].Weight := INNERVWEIGHT;
        end; //if
        tmpRange.Borders[xlInsideHorizontal].LineStyle := INNERHSTYLE;
        if INNERHSTYLE <> xlNone then begin
           tmpRange.Borders[xlInsideHorizontal].ColorIndex := INNERHCOLOUR;
           tmpRange.Borders[xlInsideHorizontal].Weight := INNERHWEIGHT;
        end; //if
        tmpRange.HorizontalAlignment := HORIZONTALCELLALIGNMENT;
        tmpRange.Font.Bold := FontBold;
        tmpRange.NumberFormat := NumberFormat;
   end; //

© Stack Overflow or respective owner

Related posts about delphi

Related posts about excel