Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Procedure TExport.ExportExcel2(CodEmp, NumOrp: Integer; CodOri: String; Relatorio: SmallInt;
- DataSet: TFdquery; Arq: String);
- Var
- ExcApp : OleVariant;
- I, J, L: Integer;
- Begin
- ExcApp := CreateOleObject('Excel.Application');
- ExcApp.Visible := False;
- ExcApp.WorkBooks.Add;
- DataSet.Close;
- DataSet.Params.ParamByName('CODEMP').AsInteger := CodEmp;
- DataSet.Params.ParamByName('CODORI').AsString := CodOri;
- DataSet.Params.ParamByName('NUMORP').AsInteger := NumOrp;
- DataSet.Params.ParamByName('RELATORIO').AsSmallInt := Relatorio;
- DataSet.SQL.Text;
- DataSet.Open;
- DataSet.First;
- FrmMenu.PnProgresso.Visible := True;
- Application.ProcessMessages;
- If DataSet.RecordCount > 0 Then
- Begin
- L := 1;
- DataSet.First;
- FrmMenu.ProgressBar1.Max := DataSet.RecordCount;
- For J := 0 To DataSet.Fields.Count - 1 Do
- Begin
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, J + 1] := DataSet.Fields[J].DisplayName;
- End;
- L := 2;
- While Not DataSet.EOF Do
- Begin
- Application.ProcessMessages;
- FrmMenu.ProgressBar1.Position := FrmMenu.ProgressBar1.Position + 1;
- FrmMenu.LblChapa.Caption := 'Processando chapa... ' +
- IntToStr(FrmMenu.ProgressBar1.Position);
- Application.ProcessMessages;
- For I := 0 To DataSet.Fields.Count - 1 Do
- Begin
- If (I = 5) Or (I = 6) Or (I = 7) Or (I = 10) Or (I = 11) Or (I = 12) Or (I = 15) Then
- Begin
- // Esp Milimetro Esquerdo
- If I = 5 Then
- Begin
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1] :=
- FormatFloat('00.00', DataSet.Fields[I].AsFloat);
- End;
- // Esp Milimetro Direito
- If I = 6 Then
- Begin
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1] :=
- FormatFloat('00.00', DataSet.Fields[I].AsFloat);
- End;
- If I = 7 Then
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1] := 'Polida';
- // Comp. Bruto
- If I = 10 Then
- Begin
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1] :=
- DataSet.Fields[I].DisplayText;
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1].NumberFormat := '##0,00_);';
- End;
- // Alt. Bruta
- If I = 11 Then
- Begin
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1] :=
- DataSet.Fields[I].DisplayText;
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1].NumberFormat := '##0,00_);';
- End;
- // Area bruta
- If I = 12 Then
- Begin
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1] := '=K' + L.ToString + '*L' +
- L.ToString;
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1].NumberFormat := '##0,0000_);';
- End;
- // Area liquida
- If I = 15 Then
- Begin
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1] := '=N' + L.ToString + '*O' +
- L.ToString;
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1].NumberFormat := '##0,0000_);';
- End;
- End
- Else
- ExcApp.WorkBooks[1].Sheets[1].Cells[L, I + 1] := DataSet.Fields[I].DisplayText;
- End;
- DataSet.Next;
- L := L + 1;
- Application.ProcessMessages;
- End;
- ExcApp.WorkBooks[1].WorkSheets[1].Range['A1', 'Y500'].Columns.AutoFit;
- Arq := 'PBA-Inspeção de Chapas GRD ' + DataSet.FieldByName('Material').AsString + '-' +
- DataSet.FieldByName('Bloco').AsString;
- ExcApp.WorkBooks[1].SaveAs(DM.CaminhoExcel + '\' + Arq);
- { Application.MessageBox(Pchar('Arquivo gerado com sucesso!' + #13 + #10 + DM.CaminhoExcel + '\'
- + Arq), 'Aviso', MB_ICONWARNING); }
- FrmMenu.AbrirPasta(DM.CaminhoExcel);
- ExcApp.Quit;
- DM.FdAtuImpresso.Params.ParamByName('codemp').AsInteger := CodEmp;
- DM.FdAtuImpresso.Params.ParamByName('codori').AsString := CodOri;
- DM.FdAtuImpresso.Params.ParamByName('numorp').AsInteger := NumOrp;
- DM.FdAtuImpresso.Execute();
- Application.ProcessMessages;
- End
- Else
- Begin
- Application.MessageBox('Nenhum arquivo gerado.', 'Aviso', MB_ICONWARNING);
- ExcApp.Quit;
- End;
- End;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement