Ver Mensaje Individual
  #3  
Antiguo 03-10-2013
Avatar de Pericles
Pericles Pericles is offline
Miembro
NULL
 
Registrado: sep 2013
Ubicación: Buenos Aires, Argentina
Posts: 24
Reputación: 0
Pericles Va por buen camino
Hola, adjunto código para generar archivo Ms Excel y agregar datos a celdas, formulas y diferentes formatos(tamaño y color de texto,ancho de filas y columnas).

Saludos
Nicolas Perichon

Código Delphi [-]

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);

var

 plantilla:OleVariant;
  Libro: _WORKBOOK;
  Hoja: _WORKSHEET;
  MiRango: OleVariant;
  xRango : ExcelRange;

begin
 //nombre archivo
 plantilla:='c:\plantilla.xls';
 ExcelApplication1.connect;
 
 libro:= ExcelApplication1.workbooks.add(plantilla,0); 
 Hoja:=ExcelApplication1.sheets[1] as _WORKSHEET; //Hoja1

 Hoja.cells.item[1,'B']:= '1';
 Hoja.cells.item[2,'B']:= '6';
 Hoja.cells.item[3,'A']:= 'TOTAL';
 Hoja.Range['B3', 'B3'].Formula := '=Sum(B1:B2)';


 Hoja.Rows.Range['A1', 'A3'].RowHeight:= 40.75; 
 Hoja.Rows.Range['B3', 'B3'].Font.[COLOR="rgb(65, 105, 225)"]Bold [/color]:= True;
 Hoja.Rows.Range['B3', 'B3'].Font.Color := clRed;
 Hoja.Range['B3', 'B3'].[Font.Size := 26;


mirango := hoja.Columns;
mirango.Columns[2].ColumnWidth := 120;

mirango.Columns[2].interior.colorIndex := 22;
// o sino  hoja.Range['B3','B3'].Interior.ColorIndex :=22;
Hoja.Rows.Range['B3', 'B3'].interior.colorIndex := 48;

ExcelApplication1.visible[0]:=true;
ExcelApplication1.disconnect;
end;

end.
Responder Con Cita