Thema: Delphi Excel Zeile löschen

Einzelnen Beitrag anzeigen

hokowa

Registriert seit: 8. Feb 2006
Ort: Berlin
8 Beiträge
 
#1

Excel Zeile löschen

  Alt 29. Okt 2008, 15:21
Hallo alle zusammen,

ich möchte in Excel eine bestimmte Zeile löschen.
Dabei gehe ich alle zeilen durch, bei erreichen der besagten Zeile --> Zeile löschen.
Habe einiges probiert, Range, Rows, UsedRange, Item usw.. geht alles nicht.

Bin für jede Hilfe dankbar

Gruß Horst


Delphi-Quellcode:
procedure TMainForm.Loeschen1Click(Sender: TObject);
var
  F_name:String;
  I, zeile, flcid,l : Integer;
begin
ZipMaster1.FSpecArgs.Clear;
Markierung :=Stringgrid1.Row;

if MessageDlg('Datei ' + StringGrid1.Cells[0, Markierung]+ ' löschen ?', mtinformation, mbYesNo,0) = mrYes then
begin
ZipMaster1.FSpecArgs.Add(StringGrid1.Cells[0, Markierung]);
ZipMaster1.Delete;
F_Name := StringGrid1.Cells[0, Markierung];
ExcelApplication1.Visible[flcid]:=False;
flcid:=GetUserDefaultLCID;
ExcelApplication1.UserControl := True;
ExcelApplication1.DisplayAlerts[flcid] := True;
ExcelApplication1.AskToUpdateLinks[flcid] := False;



   f_name:=extractfiledir(Application.ExeName) + '\benutzer.xls';

   ExcelWorkbook1.ConnectTo(ExcelApplication1.Workbooks.Open(f_name,
       emptyParam,
       True,
       emptyParam,
       emptyParam,
       emptyParam,
       emptyParam,
       emptyParam,
       emptyParam,
       emptyParam,
       emptyParam,
// emptyParam,
// emptyParam,
       emptyParam,
       emptyParam, flcid));
  ExcelWorksheet1.ConnectTo(ExcelWorkbook1.Sheets.Item[1] as ExcelWorkSheet);
  ExcelApplication1.UserControl:=true;


I := 1;
While ExcelWorksheet1.Cells.Item[I, 1].Value = F_Name do
begin
I := I +1;
End;
zeile := I;

ExcelWorksheet1.UsedRange[zeile].Delete; [b] [u] // An der Stelle soll in Excel die Zeile gelöscht werden[/u][/b]


ExcelWorksheet1.SaveAs(extractfiledir(Application.ExeName) + '\benutzer.xlsx');
ExcelWorksheet1.Disconnect;
ExcelWorkbook1.Disconnect;
ExcelApplication1.AskToUpdateLinks[flcid] := True;
ExcelWorksheet1.Application.Quit; // Schließt Excel
ExcelWorksheet1.Disconnect;
Excel := 'Unassigned';


end;
[edit=SirThornberry]Delphi-Tags gesetzt - nächstes mal bitte selbst setzen - Mfg, SirThornberry[/edit]
  Mit Zitat antworten Zitat