Autor Beitrag
uranop
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 149

Win XP, Win 7, Slackware 11, FreeBSD
D6E, php
BeitragVerfasst: Di 21.07.09 13:34 
Maahlzeit,

Jungs... ne Frage.
Ich versuche den ganzen Mittag schon folgendes zum Laufen zu bringen.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
procedure TForm7.Button5Click(Sender: TObject);
const
 xlLeft = -4131;
   xlCSV                  =     6;
   xlFormulas = -4123 ;
   xlPart = 2 ;
   xlByRows = 1 ;
   xlNext = 1  ;

var
  ExcelApp: OleVariant;
  xlUP, xlToLeft : Variant;
  strPfad : string;

begin
delay(0);
StatusBar1.Panels[1].Text :=  'XLS bearbeiten ....';
delay(0);

 ExcelApp := CreateOleObject('Excel.Application');

    ExcelApp.Workbooks.Open(Edit2.Text);
    ExcelApp.Sheets['FlatRatePCsOverview'].Range['A'+ inttostr(1),'A'+inttostr(2)].EntireRow.Delete(xlUp);
    ExcelApp.Sheets['FlatRatePCsOverview'].Range['D'+ inttostr(1),'E'+inttostr(2)].EntireColumn.Delete(xlToLeft);
    ExcelApp.FindFormat.NumberFormat := '#,##0';
    ExcelApp.Cells.Find( '.', EmptyParam, xlFormulas, xlPart, xlByRows, xlNext, False, EmptyParam, True).Activate;
    ExcelApp.Sheets['FlatRatePCsOverview'].Selection.ClearContents;
      strPfad := ExtractFilePath(ParamStr(0)); //ExtractFilePath(Application.ExeName);
    ExcelApp.ActiveWorkbook.SaveAs( strPfad + 'XLS2CSV_Pauschale' + '.csv', xlCSV);
     ExcelApp.ActiveWorkbook.Close(False);
      ExcelApp.Quit;
      ExcelApp := Unassigned;

delay(0);
StatusBar1.Panels[1].Text :=  '';
delay(0);

end;


Wenn ich auf den Button klicke, so öffnet sich Excel unsichtbar.
Es bearbeitet das File was ich übergeben habe ( aus OpenDialog ).
Das Wegschneiden der oberen beiden Zeilen und der rechten beiden Spalten funktioniert einwandfrei.
Jetzt habe ich aber gesehen das gaanz unten noch eine Zahl steht die den totalen "RowCount" angibt.
Das Ding muss raus.

Also habe ich mir in Excel nen Makro aufgezeichnet.
Das ganze schaut so aus:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
    Application.FindFormat.NumberFormat = "#,##0"

    Cells.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _

        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _

        , SearchFormat:=True).Activate

 Selection.ClearContents


Nun wollte ich das anhand goole etc so hinbiegen das das auch tut xD

Resultat ... permanente Access violations ...
Ich habe keine Ahnung warum.

kann mir da einer helfen ?

Danke sehr
ene
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 779
Erhaltene Danke: 1

Vista, XP, W2K
Delphi, .Net, Deutsch und Englisch
BeitragVerfasst: Di 21.07.09 13:56 
Wenn das immer in der selben Spalte steht, könnte man die auch durchlaufen und einfach die entsprechende Zelle löschen/leeren. Aber dafür müsste man ja wissen, ob deine Tabelle das zulässt ;) Die .Find-Geschichte finde ich nicht so prickelnd.

_________________
Wir, die guten Willens sind, geführt von Ahnungslosen, Versuchen für die Undankbaren das Unmögliche zu vollbringen.
Wir haben soviel mit so wenig so lange versucht, daß wir jetzt qualifiziert sind, fast alles mit Nichts zu bewerkstelligen.
uranop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 149

Win XP, Win 7, Slackware 11, FreeBSD
D6E, php
BeitragVerfasst: Di 21.07.09 13:59 
es steht zwar immer in der gleichen spalte, aber die laenge ist unterschiedlich.
bzw wird immer laenger.
ene
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 779
Erhaltene Danke: 1

Vista, XP, W2K
Delphi, .Net, Deutsch und Englisch
BeitragVerfasst: Di 21.07.09 14:06 
Aber es ist durch zB eine leere Zeile zu identifizieren?

_________________
Wir, die guten Willens sind, geführt von Ahnungslosen, Versuchen für die Undankbaren das Unmögliche zu vollbringen.
Wir haben soviel mit so wenig so lange versucht, daß wir jetzt qualifiziert sind, fast alles mit Nichts zu bewerkstelligen.
uranop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 149

Win XP, Win 7, Slackware 11, FreeBSD
D6E, php
BeitragVerfasst: Di 21.07.09 14:12 
nein nur das da ein feld drin ist was
eine Formatierung nach Zahl hat mit TausenderPunkt und ohne Komma.
und das ist zumindest das einzigste FEld in der XLS was so formatiert ist .

_________________
Mein worst case: Mir fehlt das Feuerzeug und das Pad für die Senseo
ene
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 779
Erhaltene Danke: 1

Vista, XP, W2K
Delphi, .Net, Deutsch und Englisch
BeitragVerfasst: Di 21.07.09 14:20 
Pseudocode (weil grad zu viele Sprachen auf einmal):

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
Do
  If .Cells("A", i).NumberFormat = "#,##0" Then 
  Begin
    .Cells("A", i).Clear;
    Exit Do;
  Else
    i++;
  End
Loop

_________________
Wir, die guten Willens sind, geführt von Ahnungslosen, Versuchen für die Undankbaren das Unmögliche zu vollbringen.
Wir haben soviel mit so wenig so lange versucht, daß wir jetzt qualifiziert sind, fast alles mit Nichts zu bewerkstelligen.
uranop Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 149

Win XP, Win 7, Slackware 11, FreeBSD
D6E, php
BeitragVerfasst: Mi 22.07.09 06:58 
Nujo mein NAmensvetter hat da nicht so ganz unrecht : P

aber mit bissl feilen gehts dann doch ...

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
procedure TForm7.Button5Click(Sender: TObject);
const
 xlLeft = -4131;
   xlCSV                  =     6;
   xlFormulas = -4123 ;
   xlPart = 2 ;
   xlByRows = 1 ;
   xlNext = 1  ;

var
  ExcelApp: OleVariant;
  xlUP, xlToLeft : Variant;
  strPfad : string;
  i: integer;

begin
delay(0);
StatusBar1.Panels[1].Text :=  'Converting XLS 2 CSV ....';
delay(0);
i := 0;

 ExcelApp := CreateOleObject('Excel.Application');

    ExcelApp.Workbooks.Open(Edit2.Text);
    ExcelApp.Sheets['FlatRatePCsOverview'].Range['A'+ inttostr(1),'A'+inttostr(2)].EntireRow.Delete(xlUp);
    ExcelApp.Sheets['FlatRatePCsOverview'].Range['D'+ inttostr(1),'E'+inttostr(2)].EntireColumn.Delete(xlToLeft);

// das hier ist des Rätselslösung \/
    i := ExcelApp.Sheets['FlatRatePCsOverview'].UsedRange.Rows.Count ;
    ExcelApp.Sheets['FlatRatePCsOverview'].Range['A'+inttostr(i)].EntireRow.Delete(xlUp);
// das hier ist des Rätselslösung /\

       strPfad := ExtractFilePath(ParamStr(0)); //ExtractFilePath(Application.ExeName);
    ExcelApp.ActiveWorkbook.SaveAs( strPfad + 'XLS2CSV_Pauschale' + '.csv', xlCSV);
     ExcelApp.ActiveWorkbook.Close(False);
      ExcelApp.Quit;
      ExcelApp := Unassigned;


delay(0);
StatusBar1.Panels[1].Text :=  '';
delay(0);

end;

_________________
Mein worst case: Mir fehlt das Feuerzeug und das Pad für die Senseo