Ir para conteúdo
Fórum Script Brasil

olssvs@msn.com

Membros
  • Total de itens

    5
  • Registro em

  • Última visita

Sobre olssvs@msn.com

olssvs@msn.com's Achievements

0

Reputação

  1. Bom dia, Quero te agradecer por estar me ajudando, mas infelizmente não funcionou. Não sei se preciso modificar o valor de alguma propriedade do stringgrid, mas realmente ele não rola o stringrid de jeito nenhum. Aqui vai todo meu código para você analisar. Mas uma vez te agradeço. unit UPrincipal; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Comobj, StdCtrls, DB, ADODB, Buttons, ExtCtrls, Registry, Printers, Grids, Math, ShlObj, ActiveX, DateUtils, ClipBrd, Shellapi, Winsock, Tlhelp32, Mask; type TFormPrincipal = class(TForm) StringGrid1: TStringGrid; BotaoImportar: TBitBtn; BotaoSair: TBitBtn; OpenDialog1: TOpenDialog; lbl1: TLabel; lbl2: TLabel; medtCNPJ: TMaskEdit; lbl3: TLabel; BotaoConsultar: TBitBtn; RG1: TRadioGroup; medtCPF: TMaskEdit; EditNome: TEdit; EditResCodigo: TEdit; EditResNome: TEdit; EditResDoc: TEdit; BotaoNovaConsulta: TBitBtn; procedure BotaoImportarClick(Sender: TObject); procedure RG1Click(Sender: TObject); procedure BotaoSairClick(Sender: TObject); procedure BotaoConsultarClick(Sender: TObject); procedure medtCPFClick(Sender: TObject); procedure medtCNPJClick(Sender: TObject); procedure EditNomeClick(Sender: TObject); procedure BotaoNovaConsultaClick(Sender: TObject); private function XlsToStringGrid(XStringGrid: TStringGrid; xFileXLS: string): Boolean; function Pesquisar(Valor : String; Coluna : Integer = 0) : Integer; { Private declarations } public { Public declarations } Result1 : integer; aux : string; end; var FormPrincipal: TFormPrincipal; pColuna : integer; implementation {$R *.dfm} function TFormPrincipal.Pesquisar(Valor : String; Coluna : Integer = 0) : Integer; var I, auxiliar : Integer; begin Result := -1; auxiliar := StringGrid1.RowCount - 1; showmessage('Auxiliar: ' + inttostr(auxiliar)); showmessage('Coluna: ' + inttostr(coluna)); showmessage('Valor: ' + valor); //showmessage('Celula: ' + StringGrid1.Cells[Coluna,I]); for I := 0 to auxiliar do begin //showmessage('Celula: ' + StringGrid1.Cells[Coluna,I]); if (StringGrid1.Cells[Coluna,I] = Valor) then begin Result := I; Break; end; end; end; function Fecha_exe(ExeFileName: variant): Integer; const PROCESSSO_FINALIZA = $0001; var ContinuaLoop: BOOL; FAquivo: THandle; FProcessoEntrada: TProcessEntry32; begin Result := 0; FAquivo := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); FProcessoEntrada.dwSize := SizeOf(FProcessoEntrada); ContinuaLoop := Process32First(FAquivo, FProcessoEntrada); while Integer(ContinuaLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessoEntrada.szExeFile)) = UpperCase(ExeFileName)) or (UpperCase(FProcessoEntrada.szExeFile) = UpperCase(ExeFileName))) then Result := Integer(TerminateProcess( OpenProcess(PROCESSSO_FINALIZA, BOOL(0), FProcessoEntrada.th32ProcessID), 0)); ContinuaLoop := Process32Next(FAquivo, FProcessoEntrada); end; CloseHandle(FAquivo); end; Function TFormPrincipal.XlsToStringGrid(xStringGrid: TStringGrid; xFileXLS: string): boolean; const xlCellTypeLastCell = $0000000B; tfontstyle = (fsbold); var XLSAplicacao, AbaXLS: OLEVariant; RangeMatrix: Variant; x, y, k, r, i: Integer; begin i := stringgrid1.Row; if i = 1 then begin stringgrid1.Canvas.Font.Style := [ ]; end; Result := False; // Cria Excel- OLE Object XLSAplicacao := CreateOleObject('Excel.Application'); try // Esconde Excel XLSAplicacao.Visible := False; // Abre o Workbook XLSAplicacao.Workbooks.Open(xFileXLS); AbaXLS := XLSAplicacao.Workbooks[ExtractFileName(xFileXLS)].WorkSheets[1]; AbaXLS.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate; // Pegar o número da última linha x := XLSAplicacao.ActiveCell.Row; // Pegar o número da última coluna y := XLSAplicacao.ActiveCell.Column+1; // Seta xStringGrid linha e coluna XStringGrid.RowCount := x-1; XStringGrid.ColCount := y; // Associaca a variant WorkSheet com a variant do Delphi RangeMatrix := XLSAplicacao.Range['A1', XLSAplicacao.Cells.Item[x, y]].Value; // Cria o loop para listar os registros no TStringGrid k := 1; repeat for r := 1 to y do XStringGrid.Cells[®, (k-1)] := RangeMatrix[k, r]; stringgrid1.cells[0, k] := inttostr(k); inc(k, 1); until k > x; RangeMatrix := Unassigned; finally // Fecha o Excel If not VarisEmpty(XLSAplicacao) then begin XLSAplicacao.Quit; XLSAplicacao := Unassigned; AbaXls := Unassigned; Result := true; end; end; end; procedure TFormPrincipal.BotaoImportarClick(Sender: TObject); begin if OpenDialog1.Execute then XlsToStringGrid(StringGrid1,OpenDialog1.FileName); Fecha_exe('excel.exe'); lbl1.Visible := true; editNome.Visible :=true; lbl2.Visible := true; lbl3.Visible := true; RG1.Visible := true; BotaoConsultar.Visible := true; end; procedure TFormPrincipal.RG1Click(Sender: TObject); begin if rg1.itemindex = 0 then begin medtCNPJ.Visible := true; medtCPF.Visible := false end else begin medtCPF.Visible := true; medtCNPJ.Visible := false end end; procedure TFormPrincipal.BotaoSairClick(Sender: TObject); begin lbl1.Visible := false; editNome.Visible := false; lbl2.Visible := false; lbl3.Visible := false; RG1.Visible := false; BotaoConsultar.Visible := false; medtCNPJ.Visible := false; medtCPF.Visible := false; end; procedure TFormPrincipal.BotaoConsultarClick(Sender: TObject); var i, j, Linha : Integer; pvalor : string; begin Result1 := 0; if editNome.Text <> '' then pvalor := editNome.Text else if medtCNPJ.Visible = True then pvalor := medtCNPJ.Text else pvalor := medtCPF.Text; j := StringGrid1.RowCount - 1; //messagebox(Stringgrid1.Handle,PChar('Indice atual '+inttostr(j)+' Pcoluna '+inttostr(pcoluna)),PChar('CONFIRMAÇÃO'), 0+64); with Stringgrid1 do begin for i := 1 to j do begin aux := StringGrid1.Cells[pColuna,i]; if pvalor = aux then begin Result1 := I; Selection := TGridRect( Rect(0, result1, 4, result1) ); Linha := Pesquisar(inttostr(result1),0); // valor e coluna showmessage(inttostr(linha)); if (Linha <> -1) then begin StringGrid1.Rows[0].IndexOf(inttostr(result1)); StringGrid1.Row := linha; showmessage('Entrou'); end; lbl1.Visible := false; editNome.Visible := false; lbl2.Visible := false; medtCNPJ.Visible := false; lbl3.Visible := false; medtCPF.Visible := false; RG1.Visible := false; BotaoConsultar.Visible := false; BotaoNovaConsulta.Visible := true; editrescodigo.Visible := true; editresnome.Visible := true; editresdoc.Visible := true; editrescodigo.Text := StringGrid1.Cells[1,i]; editresnome.Text := StringGrid1.Cells[2,i]; editresdoc.Text := StringGrid1.Cells[3,i]; messagebox(Stringgrid1.Handle,PChar('CLIENTE ENCONTRADO! '+#13+#13+'Poderá vê-lo abaixo, e também na lista que está em ordem alfabética, usando a barra de rolagem, se necessário.'),PChar('CONFIRMAÇÃO'), 0+64); Break; end end; if result1 = 0 then MessageBox(Stringgrid1.Handle,pchar('Cliente Não encontrado.'),PChar('CONSULTA'),0); end; end; procedure TFormPrincipal.medtCPFClick(Sender: TObject); begin editNome.Text := ''; medtCNPJ.Text := ''; medtCPF.Text := ''; pcoluna := 3; end; procedure TFormPrincipal.medtCNPJClick(Sender: TObject); begin editNome.Text := ''; medtCNPJ.Text := ''; medtCPF.Text := ''; pcoluna := 3; end; procedure TFormPrincipal.EditNomeClick(Sender: TObject); begin editNome.Text := ''; medtCNPJ.Text := ''; medtCPF.Text := ''; pcoluna := 2; end; procedure TFormPrincipal.BotaoNovaConsultaClick(Sender: TObject); begin editrescodigo.Visible := false; editresnome.Visible := false; editresdoc.Visible := false; BotaoNovaConsulta.Visible := false; lbl1.Visible := true; editNome.Visible := true; lbl2.Visible := true; lbl3.Visible := true; RG1.Visible := true; rg1.ItemIndex := -1; BotaoConsultar.Visible := true; end; end.
  2. Bom dia, Eu tenho um stringgrid com uma planilha do excel (clientes). Preciso fazer a pesquisa por meio de um edit do nome do cliente. Se digitar o nome completo do cliente a pesquisa já dá certo, mas o q preciso é que se eu digitar, por exemplo, apenas uma parte do nome do cliente (exemplo: o nome completo do cliente é: "Meu Cliente Com o Nome Completo", e eu digito apenas: "Meu"), como implemento essa pesquisa? Obrigado.
  3. Boa tarde Jhonas, Com esse código q você me passou ele apenas localiza a célula desejada, mas não se desloca até ela, ou seja, não rola o stringgrid para exibi-la para o usuário, e visto que minha tabela é muito grande eu precisava muito desse recurso. Obrigado.
  4. Jhonas, boa tarde Com esse código q você me passou ele apenas seleciona a linha mas não a exibe, não rola o stringgrid até onde ela está e é isso q estou precisando. Obrigado.
  5. Bom dia, Estou trabalhando com stringrid(Delphi7) importando uma planilha do Excel. Está funcionando tudo legal, ou seja, o usuário digita o nome ou o cnpj do cliente e ele é localizado no stringrid, inclusive ficando destacado com uma cor diferente. No entanto, como a lista de clientes é grande, eu necessito que, ao localizar o cliente, o stringgrid seja "rolado" e o exiba na tela. Como faço isso?
×
×
  • Criar Novo...