[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 594: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 650: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 1110: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 1110: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 1110: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 494: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 113: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5277: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5277: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5277: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3903)
Fórum Xmaker • Colocando Exportação para EXCEL no form de cadastro
Página 1 de 1

Colocando Exportação para EXCEL no form de cadastro

Enviado: Fevereiro 20th, 2015, 12:42 am
por Gilberto
Boa Noite, segue uma dica que apliquei nos meus modelos e agora é inserida em todos os cadastros criados.

Inclusão do Botão para exportação para Excel.

procedure TFormClientes.BitBtnExportarClick(Sender: TObject);
var
bm: Tbookmark;
Excel: Variant;
Linha, Coluna: integer;
begin
Screen.Cursor := crHourGlass;
try
{cria a aplicação}
Excel := CreateOleObject('Excel.Application');
except
messagebox(handle, 'MS_Excel não instalado ou imcompatível',
'Excel',
mb_iconerror + mb_ok);
raise;
end;

{guarda a posição do registro}
bm := 0;

bm := GridConsulta.DataSource.DataSet.GetBookmark;
GridConsulta.DataSource.DataSet.DisableControls;
GridConsulta.DataSource.DataSet.First;

{Adiciona pasta de trabalho}
Excel.workbooks.add;
try
{inicia variavel para começar na primeira linha}
Linha := 1;

{Cabeçalho em negrito}
for coluna := 0 to GridConsulta.Columns.Count - 1 do
begin
Excel.cells[Linha, Coluna + 1] := GridConsulta.Columns[coluna].Title.Caption;
Excel.cells[Linha, COluna + 1].font.Bold := true;
end;

{percorre todos os registros}
while not GridConsulta.DataSource.DataSet.Eof do
begin
Application.ProcessMessages;
inc(linha);

{Observe que a primeira coluna do Dbgrid é a coluna 0, mas
oara escrever na primeira coluna do MS-Excel, devemos utilizar o valor 1, então com o Excel, é
sempre o valor atual + 1}

for Coluna := 0 to GridConsulta.Columns.Count - 1 do
begin
if GridConsulta.DataSource.DataSet.fieldByName(
GridConsulta.Columns[Coluna].FieldName).DataType in
[ftFloat, ftFMTBcd] then
begin
Excel.Cells[Linha, Coluna + 1] :=
GridConsulta.DataSource.DataSet.FieldByName(
GridConsulta.Columns[Coluna].FieldName).Ascurrency;
Excel.Cells[Linha, Coluna + 1].NumberFormat :=
'#.##0,00';
end
else if GridConsulta.DataSource.DataSet.FieldByName(
GridConsulta.Columns[coluna].FieldName).datatype
= ftinteger then
begin
Excel.Cells[Linha, Coluna + 1] :=
GridConsulta.DataSource.DataSet.FieldByName(
GridConsulta.Columns[Coluna].FieldName).asinteger;
Excel.Cells[Linha, Coluna + 1].NumberFormat := '0';
end
else
Excel.cells[linha, Coluna + 1] :=
GridConsulta.DataSource.DataSet.FieldByName(
GridConsulta.Columns[coluna].FieldName).asString;
end;
GridConsulta.DataSource.DataSet.Next;
end;

{redimensiona as colunas automaticamente}
Excel.Columns.AutoFit;

{Abre APlicação}
Excel.Visible := True;

{Liberar Memoria}
Excel := Unassigned;
finally;

{Retorna para o registro selecionado anteriormente}
GridConsulta.DataSource.DataSet.GotoBookmark(bm);
GridConsulta.DataSource.DataSet.FreeBookmark(bm);
GridConsulta.DataSource.DataSet.EnableControls;
end;
Screen.Cursor := crDefault;
end;

Re: Colocando Exportação para EXCEL no form de cadastro

Enviado: Junho 14th, 2015, 5:24 pm
por Guilherme