RE: [delphi-br] [MAF] Exportar dados para Excel

2009-09-23 Por tôpico Wilson, Stephen
Bom dia

tente assim:

ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Visible := false;
ExcelApp.DisplayAlerts := false;
ExcelApp.WorkBooks.Add;
for i := 1 to 3 do
begin
  //ExcelApp.WorkBooks[1].WorkSheets.Add;Nao precisa desta linha, ja 
que existem automaticamente tres 'sheets'
  ExcelApp.WorkBooks[1].Worksheets[i].Name := IntToStr(i);   alterar os 
nomes das tres 'sheets' existentes
end;
for i := 4 to 10 do
begin
  ExcelApp.WorkBooks[1].WorkSheets.Add;
  ExcelApp.WorkBooks[1].Activesheet.Name := IntToStr(i);aqui usar 
Activesheet em vez de Worksheets[i]
end;
//i := i + 1;   Este valor nao e usado
ExcelApp.WorkBooks[1].WorkSheets.Add;
ExcelApp.WorkBooks[1].Activesheet.Name := 'Final'; 

Testei este e  funciona para mim.

 Espero ter ajudado .. ..

Att.

Steve

-Original Message-
From: delphi-br@yahoogrupos.com.br
[mailto:delphi...@yahoogrupos.com.br]on Behalf Of m_abreuferreira
Sent: 22 September 2009 23:28
To: delphi-br@yahoogrupos.com.br
Subject: [delphi-br] [MAF] Exportar dados para Excel


Pessoal,

fiz um programa para exportar dados para o Excel. Preciso criar dentro do mesmo 
XLS várias Worksheets. Pelo programa que fiz ele cria uma a mais e não está 
colocando o nome delas corretamente. Alguém já teve algum problema parecido?

Segue abaixo o programa que fiz.

Marcos Ferreira


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComObj;

type
  TForm1 = class(TForm)
Button1: TButton;
procedure ExportDBGrid(toExcel: Boolean);
procedure Button1Click(Sender: TObject);
  private
{ Private declarations }
  public
{ Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.ExportDBGrid(toExcel: Boolean);
var
  i: Integer;
  ExcelApp: Variant;
begin
  if toExcel then
  begin
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Visible := false;
ExcelApp.DisplayAlerts := false;
ExcelApp.WorkBooks.Add;
for i := 1 to 10 do
begin
  ExcelApp.WorkBooks[1].WorkSheets.Add;
  ExcelApp.WorkBooks[1].WorkSheets[i].Name := IntToStr(i);
end;
i := i + 1;
ExcelApp.WorkBooks[1].WorkSheets.Add;
ExcelApp.WorkBooks[1].WorkSheets[i].Name := 'Final';

ExcelApp.Visible := true;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExportDBGrid(True);
end;

end.





-- 
 FAVOR REMOVER ESTA PARTE AO RESPONDER ESTA MENSAGEM 





***
This e-mail and any files transmitted with it are confidential. If you are not 
the intended recipient, any reading, printing, storage, disclosure, copying or 
any other action taken in respect of this e-mail is prohibited and may be 
unlawful. If you are not the intended recipient, please notify the sender 
immediately by using the reply function and then permanently delete what you 
have received.
Content of emails received by this Trust will be subject to disclosure under 
the Freedom of Information Act 2000, subject to the specified exemptions, 
including the Data Protection Act 1998 and Caldicott Guardian principles.
This footnote also confirms that, unless otherwise stated, this email message 
has been swept by Sophos Anti-virus for the presence of computer viruses.
***



Re: [delphi-br] [MAF] Exportar dados para Excel

2009-09-23 Por tôpico Evandro Siqueira
Marcos, estou te enviando em pvt um modelo de como eu faço, ok?

m_abreuferreira escreveu:
 Pessoal,

 fiz um programa para exportar dados para o Excel. Preciso criar dentro do 
 mesmo XLS várias Worksheets. Pelo programa que fiz ele cria uma a mais e não 
 está colocando o nome delas corretamente. Alguém já teve algum problema 
 parecido?

 Segue abaixo o programa que fiz.

 Marcos Ferreira


 unit Unit1;

 interface

 uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, StdCtrls, ComObj;

 type
   TForm1 = class(TForm)
 Button1: TButton;
 procedure ExportDBGrid(toExcel: Boolean);
 procedure Button1Click(Sender: TObject);
   private
 { Private declarations }
   public
 { Public declarations }
   end;

 var
   Form1: TForm1;

 implementation

 {$R *.dfm}
 procedure TForm1.ExportDBGrid(toExcel: Boolean);
 var
   i: Integer;
   ExcelApp: Variant;
 begin
   if toExcel then
   begin
 ExcelApp := CreateOleObject('Excel.Application');
 ExcelApp.Visible := false;
 ExcelApp.DisplayAlerts := false;
 ExcelApp.WorkBooks.Add;
 for i := 1 to 10 do
 begin
   ExcelApp.WorkBooks[1].WorkSheets.Add;
   ExcelApp.WorkBooks[1].WorkSheets[i].Name := IntToStr(i);
 end;
 i := i + 1;
 ExcelApp.WorkBooks[1].WorkSheets.Add;
 ExcelApp.WorkBooks[1].WorkSheets[i].Name := 'Final';

 ExcelApp.Visible := true;
   end;
 end;

 procedure TForm1.Button1Click(Sender: TObject);
 begin
   ExportDBGrid(True);
 end;

 end.



 

   

-- 
[]’s.

Evandro Siqueira
Programador de Sistemas
L’essentiel Lingerie
(79) 3254-5511 Ramal 218
skype: evandro.lessentiel





-- 
 FAVOR REMOVER ESTA PARTE AO RESPONDER ESTA MENSAGEM 

* Para ver as mensagens antigas, acesse:
http://br.groups.yahoo.com/group/delphi-br/messages

* Para falar com o moderador, envie um e-mail para:
delphi-br-ow...@yahoogrupos.com.br
Links do Yahoo! Grupos

* Para visitar o site do seu grupo na web, acesse:
http://br.groups.yahoo.com/group/delphi-br/

* Para sair deste grupo, envie um e-mail para:
delphi-br-unsubscr...@yahoogrupos.com.br

* O uso que você faz do Yahoo! Grupos está sujeito aos:
http://br.yahoo.com/info/utos.html




[delphi-br] [MAF] Exportar dados para Excel

2009-09-22 Por tôpico m_abreuferreira
Pessoal,

fiz um programa para exportar dados para o Excel. Preciso criar dentro do mesmo 
XLS várias Worksheets. Pelo programa que fiz ele cria uma a mais e não está 
colocando o nome delas corretamente. Alguém já teve algum problema parecido?

Segue abaixo o programa que fiz.

Marcos Ferreira


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComObj;

type
  TForm1 = class(TForm)
Button1: TButton;
procedure ExportDBGrid(toExcel: Boolean);
procedure Button1Click(Sender: TObject);
  private
{ Private declarations }
  public
{ Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.ExportDBGrid(toExcel: Boolean);
var
  i: Integer;
  ExcelApp: Variant;
begin
  if toExcel then
  begin
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Visible := false;
ExcelApp.DisplayAlerts := false;
ExcelApp.WorkBooks.Add;
for i := 1 to 10 do
begin
  ExcelApp.WorkBooks[1].WorkSheets.Add;
  ExcelApp.WorkBooks[1].WorkSheets[i].Name := IntToStr(i);
end;
i := i + 1;
ExcelApp.WorkBooks[1].WorkSheets.Add;
ExcelApp.WorkBooks[1].WorkSheets[i].Name := 'Final';

ExcelApp.Visible := true;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExportDBGrid(True);
end;

end.