Exportar de um CheckListBox para o excel
Como eu exporto de um checklist(apenas checados) para uma planilha excel?
Pjava
Curtidas 0
Respostas
Joel Rodrigues
29/02/2012
Veja se este link te ajudar, ele mostra como exportar dados para Excel a partir do Delphi.
Para pegar só os valores marcados no CheckedListBox é fácil, certo?
Para pegar só os valores marcados no CheckedListBox é fácil, certo?
GOSTEI 0
Deivison Melo
29/02/2012
Basta verificar a flag (checkbox) marcada(o).
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;
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
Joel Rodrigues
29/02/2012
Foi mal, não colei o link:
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.
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
Pjava
29/02/2012
Bem, eliminei o CheckListBox e agora estou exportando direto. A rotina que gera os arquivos está abaixo:
E abaixo a chamada a esse método e a geração para o excel. O problemas está na geração do excel.
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
Pjava
29/02/2012
Ficou horrível, com as cotas code. Vou postar outra vez.
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;
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
Pjava
29/02/2012
Vou eliminar o checklistbox e exportar direto. Está lento demais a busca, porque eu carrego as tabelas em uma lista e depois vou pegando cada item e varrendo os .pas e .dfm, que devem somar tudo em mais ou menos uns 2.000 arquivos. Se tenho 200 itens, eu passo cada um 2.000 vezes. Isso demora demais e é uma lógica errada. Alguém tem alguma idéia de como melhorar isso?
GOSTEI 0