Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-11-2020
tekito tekito is offline
Miembro
 
Registrado: nov 2020
Posts: 10
Poder: 0
tekito Va por buen camino
Exportar datos a excel desde embarcadero c++

Hola, estoy intentando exportar datos de una consulta a una hoja excel, pero me da error, este es el código que utilizo:
Código PHP:
void __fastcall exportarAExcel(TADOQuery *q,String hoja,String fichero)
{
        
Variant _excel;
        
Variant _libro;
        
Variant _hoja;
        
Variant _celda;
        
Variant aux NULL;
        
String txt "";
        
int fila 1;//me almacena en qué fila del Excel estoy escribiendo
        
int columna 1;//me almacena en qué columna del Excel estoy escribiendo

        
try{
                
_excel CreateOleObject("Excel.Application");
                
//doy valor al libro a partir de la aplicación: su libro
                
_libro _excel.OlePropertyGet("Workbooks");
                
//le digo lo que tiene que hacer: añadir hojas
                
_libro.OleProcedure("Add");
                
//asigno a la hoja el primer item del libro
                
_hoja _libro.OlePropertyGet("Item",1);
                
//
                
_libro _hoja.OlePropertyGet("Worksheets");
                
//Libro=Hoja.OlePropertyGet("Worksheets");
                
_libro.OlePropertyGet("Item",1).OlePropertySet("Name",hoja);

                
//RECORRO LA CONSULTA INSERTANDO LAS CELDAS

                
_hoja _libro.OlePropertyGet("Item",1);
                
//primero relleno las cabeceras: LA PRIMERA FILA (letra en blanco negrita y fondo negro)
                
for(columna 1columna <= q->Fields->Count;columna++){
                        
txt q->Fields->Fields[columna-1]->FieldName;
                        
_hoja.OlePropertyGet("Cells").OlePropertyGet("Item",fila,columna).OlePropertySet("Value",txt );
                        
_hoja.OlePropertyGet("Cells").OlePropertyGet("Item",fila,columna).OlePropertyGet("Font").OlePropertySet("Color",clBlack);
                        
_hoja.OlePropertyGet("Cells").OlePropertyGet("Item",fila,columna).OlePropertyGet("Font").OlePropertySet("Bold",true);
                        
_hoja.OlePropertyGet("Cells").OlePropertyGet("Item",fila,columna).OlePropertyGet("Interior").OlePropertySet("ColorIndex",clBlack);
                }
                
fila 2;

                while( !
q->Eof ){
                        for(
columna 1columna <= q->Fields->Count;columna++){
                                
txt q->Fields->Fields[columna-1]->AsString;
                                
_hoja.OlePropertyGet("Cells").OlePropertyGet("Item",fila,columna).OlePropertySet("Value",txt );
                                
//vuelvo a empezar desde la primera columna: COLUMNA = 1
                        
}
                        
q->Next();//avanzo al siguiente registro: cambio de línea
                        
fila++;
                }

                
_excel.OlePropertySet("DisplayAlerts",false); //suppress the warning dialog on closing the server
                //_excel.OlePropertyGet("Workbooks").OlePropertyGet("Item",1).OleProcedure("SaveAs",fichero);
                //la pongo en visible
                
_excel.OlePropertySet("Visible",true);
                
//_excel.OleProcedure("Quit");
                //_excel = Unassigned;
        
}
        catch(
Exception *e){
                
_excel.OlePropertySet("DisplayAlerts",false); //suppress the warning dialog on closing the server
                
_excel.OleProcedure("Quit");
                
_excel Unassigned;
        }

¿Me podría ayudar?
Gracias!!

Última edición por ecfisa fecha: 12-11-2020 a las 14:29:04. Razón: Agregar etiquetas al código
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Exportar a Excel desde builder 6.0 damian2000 C++ Builder 9 22-06-2016 18:18:56
exportar datos desde excel a mysql voldemmor Varios 7 02-04-2009 15:39:03
exportar a excel desde php halizia PHP 22 29-11-2006 09:20:37
Exportar desde BDE a Excel tamara Servers 1 03-10-2003 23:05:02
Exportar desde Tabla BDE a Excel tamara Conexión con bases de datos 1 03-10-2003 18:20:03


La franja horaria es GMT +2. Ahora son las 09:41:08.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi