title: Delphi - Setting Excel Cell Background Color Gradient
body: <p>Delphi Seattle, Excel 2013.  I need to set a cell's background to be a gradient.  I can set the background color if it is a single color, but I cannot get the syntax right for gradients. Part of the challenge is that the Gradient for a cell is an IDispatch.  The following code will set a single background color.</p>
  
  <pre><code>    procedure TForm1.GradientTestClick(Sender: TObject);
  var
    oExcel : ExcelApplication;
    RawDataSheet :_Worksheet;
    ThisCell : ExcelRange;
  begin
      oExcel := CreateOleObject('Excel.Application') as ExcelApplication;
      oExcel.Visible[LOCALE_USER_DEFAULT] := True;
  
     // Add a New Workbook, with a single sheet
     oExcel.Workbooks.Add(EmptyParam, LOCALE_USER_DEFAULT);
     // Get the handle to the active Sheet, and insert some dummy data
     RawDataSheet :=  oExcel.ActiveSheet as _Worksheet;
     ThisCell := RawDataSheet.Range['A1', EmptyParam];
     ThisCell.Value2 := 10;
  
  
     // To set ONE Color
     ThisCell.Interior.Pattern := xlSolid;
     ThisCell.Interior.ColorIndex := 3;
  
     // To Set Gradient...
  
  
  end;
  </code></pre>
  
  <p>When I record an EXCEL Macro setting the gradiant I want (Linear, 2 color, Green to Yellow), the macro is</p>
  
  <pre><code>Sub Macro1()
  '
  ' Macro1 Macro
  '
  
  '
      With Selection.Interior
          .Pattern = xlPatternLinearGradient
          .Gradient.Degree = 0
          .Gradient.ColorStops.Clear
      End With
      With Selection.Interior.Gradient.ColorStops.Add(0)
          .Color = 5296274
          .TintAndShade = 0
      End With
      With Selection.Interior.Gradient.ColorStops.Add(1)
          .Color = 65535
          .TintAndShade = 0
      End With
  End Sub
  </code></pre>
  
  <p>What I should be able to do in Delphi is ...</p>
  
  <pre><code>  ThisCell.Interior.Pattern := xlPatternLinearGradient;
    ThisCell.Interior.Gradient.Degree := 0;
    ThisCell.Interior.Gradient.ColorStops.Clear;
    ThisCell.Interior.Gradient.ColorStops.Add[0].Color := 5296274;
    ThisCell.Interior.Gradient.ColorStops.Add[1].Color := 65535;
  </code></pre>
  
  <p>My challenge is that ThisCell.Interior.Gradient is an IDispatch.  How do I set the other "sub-properties" such as Degree and Colorstops?</p>
  
  <p>Thanks</p>