Autor Beitrag
dauern
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Fr 08.05.09 09:10 
hallo zusammen...
ich hätte hiermal eine frage an alle...
ich müsste ein programm schreiben das exceldateien ausliest...
aber jetzt kommt das problem : der kunde sollte durch ein edit bestimmen welche zeilen er ausgelesen haben willl...
und da ich ein delphi neuling bin habe ich so gar keine ahnung wie ich das anfangen soll..
hat mir jemand einen tipp???
mfg dauern ;)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10184
Erhaltene Danke: 1259

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 08.05.09 09:19 
Moin und :welcome: im Forum!

Schonmal in die Suche geschaut? :idea: Suche in: Delphi-Forum, Delphi-Library EXCEL OLE :les: :think: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
dauern Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Fr 08.05.09 09:28 
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:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
unit neuversuch;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  TForm1 = class(TForm)
    Laden: TButton;
    LbxText: TListBox;
    odgdialoge: TOpenDialog;
    procedure LadenClick(Sender: TObject);

  private
    { Private-Deklarationen }
    function Loadlbformexcel(strPfad: string):string;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

uses Unit4ABFRAGE, ComObj;

{$R *.dfm}


procedure TForm1.LadenClick(Sender: TObject);

var
   msLaden : TMemoryStream;
   ssText : TStringStream;
  slText: TStringList;
   strPfad : String;
   strText : String;
begin

  if odgdialoge.execute then begin
      strPfad := odgdialoge.FileName;

      Application.CreateForm(TForm4, Form4);
      if Form4.ShowModal <> mrOk then begin
        exit;
      end;
  end else begin
      exit;
  end;
  msLaden := TMemoryStream.Create;
   ssText := TStringStream.Create('');
   slText := TStringList.Create;
   try
      strText := Loadlbformexcel(strPfad);

     msLaden.LoadFromFile(strPfad);   // Laden
     msLaden.SaveToStream(ssText);
      slText.Text := ssText.DataString;
      if Form4.intAuswahl = 0 then begin // abfrage zum ersetzten oder hinzufügen
         if ExtractFileExt(strPfad) = '.txt' then begin
          lbxText.Items.Text := lbxText.Items.Text + ssText.DataString;
         end else begin
            lbxText.Items.Text := lbxText.Items.Text + strText;
         end;
      end else begin // text ersetzt werden
         if ExtractFileExt (strPfad) = '.txt'then begin
        lbxText.Items.Text := ssText.DataString;
         end else lbxText.Items.Text := strText;
      end;

   finally
     if Assigned(msLaden) then FreeAndNil(msLaden);
     if Assigned(ssText) then FreeAndNil(ssText);
      if Assigned(slText) then FreeAndNil(slText);
   end;

end;

function TForm1.Loadlbformexcel(strPfad: string): string;

const
  xlCellTypeLastCell = $0000000B;
var
   XLApp, Sheet: OLEVariant;
  RangeMatrix: Variant;
   x, y, k :integer;
   strTmp: String;

begin
  Result := '';
  XLApp := CreateOleObject('Excel.Application');
  try
    XLApp.Visible := False;
      XLApp.Workbooks.Open(strPfad);
      Sheet := XLApp.Workbooks[ExtractFileName(strPfad)].WorkSheets[1];
      Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
      x := XLApp.ActiveCell.Row;
      y := XLApp.ActiveCell.Column;
     RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]] .Value;
      strTmp := '';
      for k := 1 to x do begin
         if strTmp <> '' then begin
            strTmp := strTmp + #13#10;
         end;
        strTmp := strTmp + String(sheet.cells[k,1]);
      end;

     result := strTmp;
    finally
     if not VarIsEmpty(XLApp) then  try
    XLApp.Visible := False;
      XLApp.Workbooks.Open(strPfad);
      Sheet := XLApp.Workbooks[ExtractFileName(strPfad)].WorkSheets[1];
      Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;
      x := XLApp.ActiveCell.Row;
      y := XLApp.ActiveCell.Column;
     RangeMatrix := XLApp.Range['A1', XLApp.Cells.Item[X, Y]] .Value;
      strTmp := '';
      for k := 1 to x do begin
         if strTmp <> '' then begin
            strTmp := strTmp + #13#10;
         end;
        strTmp := strTmp + String(sheet.cells[k,1]);
      end;

     result := strTmp;
    finally
     if not VarIsEmpty(XLApp) then
     begin
       XLApp.Quit;
        XLAPP := Unassigned;
        Sheet := Unassigned;
    end;
  end;
end;
end;
end.


das ist blatt 1 wie er inzwischen die erste zeile komplett ausliest...


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:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
unit Unit4ABFRAGE;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm4 = class(TForm)
    btnUebersch: TButton;
    btnHinzu: TButton;
    btnAbbrech: TButton;
    lblText: TLabel;
    Edit1: TEdit;
    Label1: TLabel;
    procedure btnHinzuClick(Sender: TObject);
    procedure btnAbbrechClick(Sender: TObject);
    procedure btnUeberschClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    intAuswahl : integer;

    { Public-Deklarationen }
  end;

var
  Form4: TForm4;

implementation

{$R *.dfm}

procedure TForm4.btnAbbrechClick(Sender: TObject);
begin
  modalresult := mrAbort;
end;

procedure TForm4.btnHinzuClick(Sender: TObject);
begin
   intAuswahl := 0;
  modalresult := mrOk;
end;

procedure TForm4.btnUeberschClick(Sender: TObject);
begin
   intAuswahl := 1;
  modalresult := mrOk;
end;

procedure TForm4.FormCreate(Sender: TObject);
begin
  intAuswahl := -1;
end;

end.


das ist der teil wo der kundes aussucht was er haben will!



Danke für den tipp Narses... aber da steht nich das dran was ich brauche und ich glaube ich finde auch nich das was ich brauche!^^
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10184
Erhaltene Danke: 1259

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 08.05.09 10:25 
Moin!

user profile icondauern hat folgendes geschrieben Zum zitierten Posting springen:
Danke für den tipp Narses... aber da steht nich das dran was ich brauche und ich glaube ich finde auch nich das was ich brauche!^^
Und das hast du in 9 Minuten fallabschließend rausgefunden? :? Man kannst du schnell lesen... :shock:

cu :wave:
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
dauern Threadstarter
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Fr 08.05.09 10:39 
nunja ich habe mich ja vorher schon da informiert :O
und naja wie gesagt... als ich nichts gefunden habe habe ich mich hier angemeldet...
um vllt direkt auf meine frage zu kommen :)

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

okay...
danke forum für gar nix-.-