Entwickler-Ecke

Sonstiges (Delphi) - Excel Zeile löschen


hokowa - Mi 29.10.08 20:34
Titel: Excel Zeile löschen
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



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; // An der Stelle soll in Excel die Zeile gelöscht werden


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;


Xentar - Mi 29.10.08 21:28

Crosspost...
http://forum.delphi-treff.de/showthread.php?t=25079


Chemiker - Mi 29.10.08 23:15

Crosspost...

http://www.delphipraxis.net/post958429.html#958429