| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
FUENTEVILLA Cdt

Registrado: 13 Ago 2002Mensajes: 21
|
Publicado: Vie 23 Ago, 2002 4:14 pm Asunto: Excel |
|
|
Quisiera pasar los datos de dos campos de una tabla a excel.
Estos campos son rut y nombres y me gustaria que aparecieran en excel como una lista pero con un titulo ejemplo;
LISTA DE EMPLEADOS
RUT NOMBRES
11756231-5 juan perez
15879451-6 claudia rojas
Gr@cias... |
|
| Volver arriba |
|
 |
Marcos Invitado
|
Publicado: Vie 23 Ago, 2002 5:28 pm Asunto: Excel |
|
|
Aqui te envío algo haber si funciona.
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <Comobj.hpp> // Añadir esta linea
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
//Para abrir excel
Variant xlApp;
xlApp = CreateOleObject("Excel.Application");
//hacer visible EXCEL
xlApp.Exec(PropertySet("Visible") << true);
//Acceso a un objeto libro
Variant xlBooks = xlApp.Exec(PropertyGet("Workbooks"));
//crea un nuevo archivo
xlBooks.Exec(Procedure("Add"));
//elige el primer libro de la aplicación
Variant xlBook = xlBooks.Exec(PropertyGet("Item") << 1);
//crea un acceso a un objeto hoja
Variant xlSheets = xlBook.Exec(PropertyGet("Worksheets"));
//Elige una hoja
Variant xlSheet = xlSheets.Exec(PropertyGet("Item") << 1);
//En esta parte es en donde agregas los datos
Variant VRange;
VRange = xlSheet.Exec(PropertyGet("Range") << "A4");
VRange.Exec(PropertySet("Value") << "RUT");
VRange = xlSheet.Exec(PropertyGet("Range") << "B4");
VRange.Exec(PropertySet("Value") << "NOMBRE");
int fila=5;
while(!Table1->Eof)
{
VRange = xlSheet.Exec(PropertyGet("Range") << "A"+IntToStr(fila));
VRange.Exec(PropertySet("Value") << DBEdit1->Text);
VRange = xlSheet.Exec(PropertyGet("Range") << "B"+IntToStr(fila));
VRange.Exec(PropertySet("Value") << DBEdit2->Text);
Table1->Next();
fila++;
}
//Guarda el archivo
xlBook.Exec(Procedure("SaveAs") << "c:\\archivo.xls");
//-------- Cierra excel
xlApp.Exec(PropertySet("Visible") << false);
xlApp.Exec(Procedure("Quit"));
xlApp.Clear();
}
//---------------------------------------------------------------------------
DBEdit1 y DBEdit2 son la referencia de los dos campos de la tabla |
|
| Volver arriba |
|
 |
|