Club Builder - Foros de discusión Club Builder
Foro de C++Builder en español
 
 FAQFAQ   BuscarBuscar   MiembrosMiembros   Grupos de UsuariosGrupos de Usuarios   RegistrarseRegistrarse 
 PerfilPerfil   Entra para ver tus mensajes privadosEntra para ver tus mensajes privados   EntrarEntrar 

Excel

 
Publicar nuevo tema   Responder al tema    Foros de discusión -> Consultas
Ver tema anterior :: Ver tema siguiente  
Autor Mensaje
Mensaje    Asunto: Excel Responder citando

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
Ver perfil de usuario Enviar mensaje privado
Mensaje    Asunto: Excel Responder citando

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
Mostrar mensajes de anteriores:   
Cambiar a:  
No puedes publicar temas nuevos en este foro
No puedes responder a temas en este foro
No puedes editar tus mensajes en este foro
No puedes borrar tus mensajes en este foro
No puedes votar en las encuestas de este foro


Hosting WordPress Indedmedia desde 3,99 €
© 2002–2026 Club Builder · Funciona con phpBB.