Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 30-03-2016
Avatar de Soa Pelaez
Soa Pelaez Soa Pelaez is offline
Miembro
 
Registrado: nov 2015
Posts: 133
Poder: 9
Soa Pelaez Va por buen camino
Finalizar proceso OleObject Excel

Buen día.

Si me pudieran ayudar estoy tratando con excel mediante OleObject pero al finalizarlo y cerrar el OleObject el proceso de excel se queda en el administrador de tareas tantas veces como ejecute el código.

El código es el siguiente

Código Delphi [-]
function CargStrinGrid(AGrid: TStringGrid;
  AXLSFile: string): Boolean;
const
  xlCellTypeLastCell = $0000000B;
var
  XLApp, Sheet: OLEVariant;
  RangeMatrix: Variant;
  x, y, k, r: Integer;
begin
  Result := False;
  // Create Excel-OLE Object
  XLApp := CreateOleObject('Excel.Application');
  try
    // Hide Excel
    XLApp.Visible := False;
    // Open the Workbook
    XLApp.Workbooks.Open(AXLSFile);
    // Sheet := XLApp.Workbooks[1].WorkSheets[1];
    Sheet := XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];
    Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
    // Get the value of the last row
    x := XLApp.ActiveCell.Row;
    // Get the value of the last column
    y := XLApp.ActiveCell.Column;
    // Set Stringgrid's row &col dimensions.
    AGrid.RowCount := x;
    AGrid.ColCount := y;
    // Assign the Variant associated with the WorkSheet to the Delphi Variant
    RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;
    //  Define the loop for filling in the TStringGrid
    k := 1;
    repeat
      for r := 1 to y do
        AGrid.Cells[(r - 1), (k - 1)] := RangeMatrix[K, R];
      Inc(k, 1);
      AGrid.RowCount := k + 1;
    until k > x;
    // Unassign the Delphi Variant Matrix
    RangeMatrix := Unassigned;
  finally
    // Quit Excel
    if not VarIsEmpty(XLApp) then
    begin
//      XLApp.DisplayAlerts := False;
      XLApp.Quit;
      XLAPP := Unassigned;
      Sheet := Unassigned;
      Result := True;
  end;

No veo el error he buscado soluciones y como lo tengo es la forma en que lo hacen, si alguien me puede colaborar se lo agradecería.

Última edición por Soa Pelaez fecha: 30-03-2016 a las 04:32:07.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Excel no es liberado de memoria al final de un proceso de automatización con Delphi shoulder Varios 3 06-07-2016 20:33:45
Como finalizar debug marlulipe Varios 1 15-06-2007 03:19:33
Como Liberar un OleObject ???? AGAG4 Varios 0 13-05-2006 01:55:50
Finalizar una Condición jdangosto OOP 3 02-12-2005 08:57:38
Liberar proceso de Excel lgarcia Servers 4 01-04-2005 00:16:26


La franja horaria es GMT +2. Ahora son las 16:32:54.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi