По кнопке происходит вывод в эксель
| Код | procedure TForm2.Button2Click(Sender: TObject); var curDate,endDate:TDate; excel,book,Sheet:OleVariant;
begin curDate:=DateTimePicker2.Date; endDate:=DateTimePicker3.Date+1;
Excel:=CreateOleObject('Excel.Application'); Excel.Application.EnableEvents:=False; Excel.Visible:=False; Book:=Excel.WorkBooks.Add; Sheet:=Excel.ActiveWorkBook.Worksheets[1]; Excel.Range[ Excel.Cells[1, 1], Excel.Cells[10, 10] ].Select;
//+--=+-=+-=+-=+-=+-=+-=+-=+-=+-=+-= while not (DateToStr(curDate)=DateToStr(endDate)) do begin SetFilter(DM.Main,Edit1.Text,curDate); SG.DBtoSG(DM.Main); //SG.ShowSG(StringGrid1); SG.Calculate; //SG.ShowCalc(StringGrid2); SG.OutToExcel(Excel,0,3); //<<<------ Здесь будет моя процедура
curDate:=curDate+1; end; //+--=+-=+-=+-=+-=+-=+-=+-=+-=+-= Excel.Visible:=true; Sheet:= UnAssigned; Book := UnAssigned; Excel:= UnAssigned; end;
|
Хочу часть вывода таблицы вынести в процедуру, написал так:
| Код | Procedure TSGRid.OutToExcel(Var excel: OleVariant; StartCol,StartRow:integer); Var i,j,Col,Row,Count:integer; tmp:string; begin col:=startCol; row:=StartRow; Count:=0;
for j:=0 to 23 do If SGar[4,j]=NotEmpty then begin Excel.Range[Excel.Cells[Row, Col+Count],EmptyParam].Value:=IntToStr(j)+':00'; if Sgar[0,j]<>Empty then tmp:=FloatToStr(SGar[0,j] / 10) else tmp:='*'; Excel.Range[Excel.Cells[Row+1, Col+Count],EmptyParam].Value:=tmp;
if Sgar[1,j]<>Empty then tmp:=FloatToStr(SGar[1,j] / 100) else tmp:='*'; Excel.Range[Excel.Cells[Row+1, Col+Count],EmptyParam].Value:=tmp;
if Sgar[2,j]<>Empty then tmp:=IntToStr(SGar[2,j]) else tmp:='*'; Excel.Range[Excel.Cells[Row+1, Col+Count],EmptyParam].Value:=tmp;
if Sgar[3,j]<>Empty then tmp:=IntToStr(SGar[3,j]) else tmp:='*'; Excel.Range[Excel.Cells[Row+1, Col+Count],EmptyParam].Value:=tmp; Inc(Count); end; end;
|
При запуске выводится ошибка, на месте первого обращения к excel в процедуре, я так понимаю ошибка из за того что я передаю Excel переменную в процедуру не правильно, надо адрес передавать или как правильней сделать? |