Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

export podataka iz tabele

[es] :: Pascal / Delphi / Kylix :: export podataka iz tabele

[ Pregleda: 3144 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

dejov
Dejan Jovic
Zrenjanin

Član broj: 17537
Poruke: 88
*.dialup.neobee.net.



Profil

icon export podataka iz tabele20.07.2004. u 15:55 - pre 240 meseci
Imam jednu adotable. Kako da (npr klikom na dugme) exportujem podatke iz te tabele u npr fajl *.xls?
 
Odgovor na temu

marcony86
Absolute Freelancer
Kapedunum/Singidunum

Član broj: 12256
Poruke: 225
*.ptt.yu



+1 Profil

icon Re: export podataka iz tabele24.07.2004. u 13:35 - pre 240 meseci
Ja to radim pomoću TADOQuery, tako što napravim HTML tabelu, koju zatim sačuvam kao *.xls fajl, koji funkcioniše kao normalna tabela kada se otvori u Excel-u.

Code:

procedure TForm1.Button4Click(Sender: TObject);
var
html: widestring;
excelfile: TextFile;
i: integer;
begin
SaveDialog1.InitialDir := ExtractFilePath(Application.ExeName);
SaveDialog1.Filter := 'Microsoft Excel (*.xls)|*.xls';
SaveDialog1.FileName := 'katalog.xls';
SaveDialog1.DefaultExt := '*.xls';
SaveDialog1.Execute;
.
.
.
ADOQuery3.SQL.Text := 'SELECT * FROM filmovi';
ADOQuery3.Open;
html:= html + '<table border="1" width="100%">' + #13#10;
html:= html + '<tr><td colspan="5" align="center"><i>Katalog Filmova</i></td></tr>' + #13#10;
html:= html + '<tr>' + #13#10;
html:= html + '<td>' + '<b>' + 'ID broj filma' + '</b>' + '</td>';
html:= html + '<td>' + '<b>' + 'Naslov filma' + '</b>' + '</td>';
html:= html + '<td>' + '<b>' + 'Zanr' + '</b>' + '</td>';
html:= html + '<td>' + '<b>' + 'Distributer' + '</b>' + '</td>';
html:= html + '<td>' + '<b>' + 'Tip medijuma' + '</b>' + '</td>' + #13#10;
html:= html + '</tr>' + #13#10;
while not AdoQuery3.Eof do
begin
html:= html + '<tr>' + #13#10;
for i:=0 to AdoQuery3.FieldCount-1 do
begin
html:= html + '<td>';
html:= html + ADOQuery3.Fields[i].AsString;
html:= html + '</td>' + #13#10;
end;
html:= html + '</tr>' + #13#10;
ADOQuery3.Next;
end;
html:= html + '</table>';
Memo1.Text := html;
AssignFile(excelfile, SaveDialog1.FileName);
Rewrite(excelfile);
WriteLn(excelfile, html);
CloseFile(excelfile);
ShowMessage('Fajl je uspesno exportovan!');
end;
end;
 
Odgovor na temu

reiser

Član broj: 7895
Poruke: 2314



+102 Profil

icon Re: export podataka iz tabele24.07.2004. u 14:05 - pre 240 meseci
Ili downloaduj OfficePartner komponentu sa http://sourceforge.net/projects/tpofficepartner/

Meni se svidja, prilicno je mocna, mozes da uradis sve sto ti treba.

Evo kako bi otprilike trebao da izgleda source :
Code:

function TMembersListExportWindow.SaveList(const Path : String) : String;
const
  TNam      : Array[1..10] of String = ('IDNum',
                                        'FirstName',
                                        'LastName',
                                        'Address',
                                        'BirthPlace',
                                        'BirthDate',
                                        'PhoneNumber',
                                        'PaperNum',
                                        'JoinDate',
                                        'Status');
  TNamTr    : Array[1..10] of String = ('Broj',
                                        'Ime',
                                        'Prezime',
                                        'Adresa',
                                        'Mesto Rodjenja',
                                        'Datum Rodjenja',
                                        'Broj Telefona',
                                        'Broj Licne Karte',
                                        'Datum Uclanjenja',
                                        'Status');
  ColWidths : Array[1..10] of Integer = (8, 22, 25, 30, 22, 21, 25, 22, 15, 15);
var
  CTNum     : Byte;
  SelString : String;
  SortErr   : Boolean;
  C1        : Integer;
begin
  result := 'Lista uspesno snimljena !';
  CTNum := 65;
  SortErr := FALSE;

  SelString := 'SELECT ';

  For C1 := 1 to 10 Do
    If TCheckBox(FindComponent('CheckBox' + IntToStr(C1))).Checked Then
      SelString := SelString + TNam[C1] + ',';

  If SelString = 'SELECT ' Then
  Begin
    result := 'Morate selektovati bar jedan podatak koji ce se nalaziti u listi !';
    Exit;
  End;

  SelString := Copy(SelString, 1, Length(SelString) - 1) + ' FROM bases\Members.db ORDER BY ';

  For C1 := 1 to 10 Do
    If TRadioButton(FindComponent('RadioButton' + IntToStr(C1))).Checked Then
      If TCheckBox(FindComponent('CheckBox' + IntToStr(C1))).Checked Then
        SelString := SelString + TNam[C1]
      else
        SortErr := TRUE;

  If SortErr Then
  Begin
    result := 'Lista mora da bude sortirana po polju koje ce se nalaziti u listi !';
    Exit;
  End;

  OpExcel1.Connected := TRUE;
  OpExcel1.Workbooks[0].Worksheets[0].Name := 'Lista Clanova';

  Query1.Close;
  Query1.SQL.Clear;
  Query1.SQL.Add(SelString);
  Query1.Open;

  With OpExcel1.Workbooks[0].Worksheets[0].Ranges[0] Do
  Begin
    Address := 'A1';
    OfficeModel := OpDataSetModel1;
    Populate;
  End;

  For C1 := 1 to 10 Do
    If TCheckBox(FindComponent('CheckBox' + IntToStr(C1))).Checked Then
      With OpExcel1.Workbooks[0].Worksheets[0].Ranges[C1 - 1] Do
      Begin
        Address := Chr(CTNum) + '1';
        SimpleText := TNamTr[C1];
        Color := clSkyBlue;
        Borders := [xlbLeft,xlbRight,xlbTop,xlbBottom];
        BorderLineWeight := xlbwThin;
        ColumnWidth := ColWidths[C1];
        FontAttributes := [xlfaBold];
        HorizontalAlignment := xlchaCenter;
        RowHeight := 23;
        VerticalAlignment := xlcvaCenter;
        Inc(CTNum);
      End;

  OpExcel1.Workbooks[0].SaveAs(Path);
  OpExcel1.Connected := FALSE;
end;
 
Odgovor na temu

dejov
Dejan Jovic
Zrenjanin

Član broj: 17537
Poruke: 88
*.dialup.neobee.net.



Profil

icon Re: export podataka iz tabele24.07.2004. u 20:11 - pre 240 meseci
Bio sam ubedjen da postoji jednostavnija varijanta :)
 
Odgovor na temu

[es] :: Pascal / Delphi / Kylix :: export podataka iz tabele

[ Pregleda: 3144 | Odgovora: 3 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.