Ver Mensaje Individual
  #1  
Antiguo 05-07-2013
steelha steelha is offline
Miembro
 
Registrado: mar 2012
Posts: 158
Reputación: 13
steelha Va por buen camino
Eliminar Fila en Hoja de Excel

Buenas, he tratado de buscar como eliminar una fila de un archivo en excel desde delphi, y he tratado varios métodos sin ningún resultado acá dejo parte del código para que sea verificado a ver que le hace falta. Aaah Al final de eliminar las filas me interesa guardar el archivo con los cambios.

Código Delphi [-]
procedure TfrmGenerarTxt.Button1Click(Sender: TObject);
Var
  i     : Integer;
  j     : Integer;
  si    : String;
  h     : integer;
  ultfil: Integer;
  excel : OleVariant;
  Book  : OleVariant;
  hoja  : _Worksheet;
begin
  with UArchivoExcel do
  begin
    InitialDir := GetCurrentDir;
    Options := [ofFileMustExist];
    Filter  := 'Excel 97-2003|*.xls|Excel 2007-2010|*.xlss';
    FilterIndex := 1;

    if Execute then
      lstArchivo.Lines.Text := FileName
    else
      ShowMessage('Selección de Archivo Cancelada por el usuario');
  end;

  try
    ExcelApp.Workbooks.Open(Trim(lstArchivo.Lines.Text), EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 
                            EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0);
    hoja := ExcelApp.Worksheets.Item[1] as _WorkSheet;
    ExcelApp.Cells.SpecialCells(xlCellTypeLastCell,EmptyParam).Activate;
    ultfil := ExcelApp.ActiveCell.Row;
    ShowMessage(IntToStr(ultfil));

  finally
    ShowMessage(IntToStr(ultfil));
    for i:=1 to ultfil do
    begin
      hoja.Cells.Range['A'+IntToStr(i),'A'+IntToStr(i)].Activate;
      If not VarIsNumeric(LeftStr(ExcelApp.Range['A'+IntToStr(i),'A'+IntToStr(i)].Value,1)) then
      begin
//        hoja.Cells.Range['A'+IntToStr(i),'A'+IntToStr(i)].Row.Delete;
      end;
    end;
  end;
  ExcelApp.Workbooks.Close(0);
end;

Última edición por Casimiro Notevi fecha: 05-07-2013 a las 21:33:19.
Responder Con Cita