调用Excel的函数,就相当于给结果单元格设置公式, <br><br>procedure TForm1.Button1Click(Sender: TObject); <br>begin <br> xlapp := CreateOleObject('excel.application'); <br> xlapp.visible := true; <br> xlApp.DisplayAlerts := False; <br> xlapp.workbooks.add; <br> xlSheet := xlapp.workbooks[1].sheets[1]; <br>end; <br><br>// set excel cell value <br>procedure TForm1.Button2Click(Sender: TObject); <br>begin <br> xlSheet.Cells(1, 1) := '1'; <br> xlSheet.Cells(1, 2) := '2'; <br> xlSheet.Cells(1, 3) := '=SUM(A1:B1)'; //求和 <br> xlSheet.Cells(1, 4) := '=AVERAGE(A1:B1)';//求平均值