Ver Mensaje Individual
  #2  
Antiguo 07-11-2012
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
cmfab,

Revisa este código:
Código Delphi [-]
unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  Excel, WrkS, WrkB : OLEVariant;
  XlFileFormat : Variant;
  ConsecutiveDelimiter : Variant;
  Tab : Variant;
  Comma : Variant;

begin

  Excel := createOleObject('Excel.Application');

  Excel.DisplayAlerts:=false;

  ConsecutiveDelimiter := True;
  Comma := True;

  Excel.Workbooks.Opentext('D:\TestFile_Comma.txt',
                           EmptyParam,
                           EmptyParam,
                           EmptyParam,
                           EmptyParam,
                           ConsecutiveDelimiter,
                           EmptyParam,
                           EmptyParam,
                           Comma,
                           EmptyParam,
                           EmptyParam,
                           EmptyParam,
                           EmptyParam,
                           EmptyParam,
                           EmptyParam,
                           EmptyParam,
                           EmptyParam,
                           EmptyParam);

  XlFileFormat :=  51; // xlWorkbookDefault;

  Excel.WorkBooks[1].WorkSheets[1].Name := 'CSV';

  WrkB := Excel.WorkBooks[1].WorkSheets['CSV'];
 
  WrkB.SaveAs('D:\ExcelFile.xlsx',XlFileFormat);

  Excel.quit;

end;

end.
El código anterior permite generar un WorkBook de Excel 2010 a partir de un archivo de texto en formato CSV usando Delphi 7.

Revisa estos links:
Cita:
Excel 2010 Object Model Changes Since Earlier Versions
http://msdn.microsoft.com/en-us/library/ee836187.aspx

Workbooks.OpenText Method (Excel)
http://msdn.microsoft.com/en-us/libr.../ff837097.aspx

Workbook.SaveAs Method (Excel)
http://msdn.microsoft.com/en-us/libr.../ff841185.aspx

XlFileFormat Enumeration
http://msdn.microsoft.com/en-us/libr.../ff198017.aspx

Excel specifications and limits
http://office.microsoft.com/en-us/ex...in=HP005199291
Espero sea útil

Nelson.
Responder Con Cita