Автор: DroN_S
Дата сообщения: 10.05.2006 21:57
vovanzp
Код:
Procedure SendtoExcel(ShFile: String; Querys: TQuery);
Var
ExcelApp, Workbook, Range, Cell1, Cell2, ArrayData: Variant;
BeginCol, BeginRow, j: integer;
RowCount, ColCount: Integer;
Begin
BeginCol := 1;
BeginRow := 3;
RowCount := Querys.RecordCount;
ColCount := Querys.FieldDefs.Count;
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Application.EnableEvents := false;
Workbook := ExcelApp.WorkBooks.Add(ShFile);
ArrayData := VarArrayCreate([1, RowCount, 1, ColCount], varVariant);
Querys.DisableControls;
Querys.First;
While Not Querys.eof Do
Begin
For J := 1 To Querys.FieldDefs.Count Do
Begin
ArrayData[Querys.RecNo, J] :=
Querys.FieldbyName(Querys.FieldDefs.Items[j - 1].DisplayName).value;
End;
Querys.Next;
End;
Querys.EnableControls;
Cell1 := WorkBook.WorkSheets[1].Cells[BeginRow, BeginCol];
Cell2 := WorkBook.WorkSheets[1].Cells[BeginRow + RowCount - 1,
BeginCol + ColCount - 1];
Range := WorkBook.WorkSheets[1].Range[Cell1, Cell2];
Range.Value := ArrayData;
ExcelApp.Visible := True;
End;