Fórum Exportar de um CheckListBox para o excel #413503
29/02/2012
0
Pjava
Curtir tópico
+ 0Posts
29/02/2012
Joel Rodrigues
Para pegar só os valores marcados no CheckedListBox é fácil, certo?
Gostei + 0
29/02/2012
Deivison Melo
Veja esse exemplo (não tenho o delphi aqui no trabalho):
while not query.eof do
begin
if query.checkboxMarcado = S then
\\faça o que quiser aqui!!!!!
end;
end;
Gostei + 0
29/02/2012
Joel Rodrigues
http://www.planetadelphi.com.br/dica/5329/exportando-para-o-excel
Bem, como falei, verificar só os itens marcados é fácil, basta fazer como o amigo acima sugeriu.
Gostei + 0
29/02/2012
Pjava
function TForm1.TextFoundInFile(path: string; const FileMask:string; const tipo, tabela: string): TStrings;
var
SR: TSearchRec;
txt: TextFile;
Row: string;
Found: Boolean;
i: Integer;
NroExt: TStrings;
begin
NroExt:= TStringList.Create;
try
NroExt.Delimiter:= ;;
NroExt.DelimitedText:= FileMask;
path := IncludeTrailingPathDelimiter(path);
Result := TStringList.Create;
for i:= 0 to NroExt.Count - 1 do
begin
if FindFirst(path + NroExt[i], faAnyFile - faDirectory, SR) = 0 then
repeat
AssignFile(txt,path + SR.Name);
Reset(txt);
Found:= False;
while not Eof(txt) and not Found do
begin
Readln(txt, Row);
if Pos(tabela, Row) > 0 then
begin
Result.Add(tipo + ; + tabela + ; + SR.Name);
Found:= True
end
end;
CloseFile(txt);
until FindNext(SR) <> 0
end
finally
NroExt.Free;
end
end;E abaixo a chamada a esse método e a geração para o excel. O problemas está na geração do excel.
procedure TForm1.VarrerClick(Sender: TObject);
begin
ClientDataSet1.Open;
pth := IncludeTrailingPathDelimiter(edtDir.Directory);
while not ClientDataSet1.Eof do
begin
TextFoundInFile(pth,*.pas;*.dfm,ClientDataSet1.FieldByName(xtype).AsString,ClientDataSet1.FieldByName(name).AsString).SaveToFile(D:\Teste\LISTA.xls);
ClientDataSet1.Next;
end;
end;Gostei + 0
29/02/2012
Pjava
O método
function TForm1.TextFoundInFile(path: string; const FileMask:string; const tipo, tabela: string): TStrings;
var
SR: TSearchRec;
txt: TextFile;
Row: string;
Found: Boolean;
i: Integer;
NroExt: TStrings;
begin
NroExt:= TStringList.Create;
try
NroExt.Delimiter:= ;;
NroExt.DelimitedText:= FileMask;
path := IncludeTrailingPathDelimiter(path);
Result := TStringList.Create;
for i:= 0 to NroExt.Count - 1 do
begin
if FindFirst(path + NroExt[i], faAnyFile - faDirectory, SR) = 0 then
repeat
AssignFile(txt,path + SR.Name);
Reset(txt);
Found:= False;
while not Eof(txt) and not Found do
begin
Readln(txt, Row);
if Pos(tabela, Row) > 0 then
begin
Result.Add(tipo + ; + tabela + ; + SR.Name);
Found:= True
end
end;
CloseFile(txt);
until FindNext(SR) <> 0
end
finally
NroExt.Free;
end
end;
A chamada
procedure TForm1.VarrerClick(Sender: TObject);
begin
ClientDataSet1.Open;
pth := IncludeTrailingPathDelimiter(edtDir.Directory);
while not ClientDataSet1.Eof do
begin
TextFoundInFile(pth,*.pas;*.dfm,ClientDataSet1.FieldByName(xtype).AsString,ClientDataSet1.FieldByName(name).AsString).SaveToFile(D:\Teste\LISTA.xls);
ClientDataSet1.Next;
end;
end;
Gostei + 0
01/03/2012
Pjava
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)