Touchsoftwares Master


Registrado: 16 Dic 2002Mensajes: 869Ubicación: MEXICO Playa del Carmen
|
Publicado: Jue 24 Nov, 2005 10:52 pm Asunto: La exportacion de un TQuery a Excel.ya no funciona |
|
|
Dejo de funcionar
magicamente..ayuda..no le movi nada al codigo
| Código: |
//------------------------------------------------------------
void ExportarExcel(TDataSet *qry)
{
Variant vRango;
// ANTES DE AQUI..funcin..luego marca un error de violacion
Variant vExcel=CreateOleObject("Excel.Application");
//-------- crea acceso al objeto 'libro'/workbook
// Variant vHoja= vExcel.Exec(PropertyGet("Workbooks"));
int row = 1;
String COLUMNA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";//para los nombres de columna
//cabeceras
for (int i = 0; i < qry->FieldDefs->Count; i++)
{
TFieldDef *fd = qry->FieldDefs->Items[i];
if(i<=25)
vExcel.OlePropertyGet("Range",COLUMNA.SubString(i+1,1)+IntToStr(row)).OleProcedure("Select");
if(i>25 && i <=51)
vExcel.OlePropertyGet("Range","A"+COLUMNA.SubString(i+1-26,1)+IntToStr(row)).OleProcedure("Select");
if(i>51 && i <=77)
vExcel.OlePropertyGet("Range","B"+COLUMNA.SubString(i+1-26,1)+IntToStr(row)).OleProcedure("Select");
if(i>77 && i <=103)
vExcel.OlePropertyGet("Range","C"+COLUMNA.SubString(i+1-78,1)+IntToStr(row)).OleProcedure("Select");
vExcel.OlePropertyGet("ActiveCell").
OlePropertySet("Value",fd->Name);
}
row++;
row++;
qry->First();
while(!qry->Eof)
{
for(int col=0;col<qry->FieldCount;col++)
{
if(col<=25)
vExcel.OlePropertyGet("Range",COLUMNA.SubString(col+1,1)+IntToStr(row)).OleProcedure("Select");
if(col>25 && col <=51)//if(col>26 <=52)
vExcel.OlePropertyGet("Range","A"+COLUMNA.SubString(col+1-26,1)+IntToStr(row)).OleProcedure("Select");
if(col>51 && col <=77)
vExcel.OlePropertyGet("Range","B"+COLUMNA.SubString(col+1-52,1)+IntToStr(row)).OleProcedure("Select");
if(col>77 && col <=103)
vExcel.OlePropertyGet("Range","C"+COLUMNA.SubString(col+1-78,1)+IntToStr(row)).OleProcedure("Select");
vExcel.OlePropertyGet("ActiveCell").
OlePropertySet("Value",qry->Fields->Fields[col]->AsString);
}
qry->Next();
row++;
}
/* for (int i=1;i<qry->FieldDef100;i++) {
char* nombreCelda;
AnsiString tmpCelda;
tmpCelda="A"+IntToStr(i);
nombreCelda=tmpCelda.c_str();
vRango=vHoja.OlePropertyGet("Range",nombreCelda);
vRango.OlePropertySet("Value",1);
}*/
// vExcel=vHoja=Unassigned;
}
//---------------------------------------
|
Cabeceras
En funciones.cpp
| Código: |
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <conio.h>
#include <winbase.h>
#include <math.h>
#include <registry.hpp>
#include<olectl.h>
#include <winsock2.h>
#include <utilcls.h>
#include <memory>
#include <jpeg.hpp>
#include <windows.h>
|
en funciones.h
| Código: |
#include <Printers.hpp>
#include <Winspool.hpp>
#include <db.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
#include <jpeg.hpp>
#include <dbtables.hpp>
#include <typinfo.hpp>
|
_________________ Ing. Gabriel Góngora Navarrete
TouchSoftwares Inc
http://www.touchsoftwares.com |
|