
16/12/2013, 11:15
|
| | Fecha de Ingreso: diciembre-2013
Mensajes: 1
Antigüedad: 11 años, 3 meses Puntos: 0 | |
Problema exportando un reporte a excel Hola a todos.
Estoy trabajando en una pequeña aplicación con una base de datos en MySql la cual contiene una sola tabla llamada "personas" logro realizar las busquedas y mostrarlas en el grid sin problema alguno, pero al momento de exportar el resultado del grid tengo problema ( estoy usando un query, datasource y database ). El codigo que estoy usando es el siguiente:
Código:
void __fastcall TForm1::Button6Click(TObject *Sender)
{
//declare variables
Variant XL,v0,v1,v2,v3;
//open excel application
XL=Variant::CreateObject("excel.application");
//Get workbook
v0=XL.OlePropertyGet("Workbooks");
//add one work book
v0.OleProcedure("Add");
//select workbook number 1
v0=v0.OlePropertyGet("Item",1);
//Get worksheet
v0=v0.OlePropertyGet("WorkSheets");
// add one work sheet
v0.OleFunction("Add");
//select worksheet number 1
v0=v0.OlePropertyGet("Item",1);
//get a cell
v1 = v0.OlePropertyGet("Cells");
//pb->Min = 0;
//pb->Position = 0;
long lnContador = 1;
//Se pinta el encabezado
v1.OlePropertyGet("Item",lnContador,1).OlePropertySet("Value","Codigo");
v1.OlePropertyGet("Item",lnContador,2).OlePropertySet("Value","Nombre");
v1.OlePropertyGet("Item",lnContador,3).OlePropertySet("Value","Edad");
v1.OlePropertyGet("Item",lnContador,4).OlePropertySet("Value","Genero");
lnContador++; //Incrementamos el renglon en excel
Query1->First();
//pb->Max = Query1->RecordCount;
while(!Query1->Eof)
{
//pb->Position++;
//Se pintan los valores de las columnas
if(!Query1->FieldByName("idCiudadano")->Value.IsNull())
v1.OlePropertyGet("Item",lnContador,1).OlePropertySet("Value",(/*(AnsiString)*/Query1->FieldByName("idCiudadano")->Value)/*.c_str()*/);
if(!Query1->FieldByName("nomCiudadano")->Value.IsNull())
v1.OlePropertyGet("Item",lnContador,2).OlePropertySet("Value",(/*(AnsiString)*/Query1->FieldByName("nomCiudadano")->Value)/*.c_str()*/);
if(!Query1->FieldByName("edad")->Value.IsNull())
v1.OlePropertyGet("Item",lnContador,3).OlePropertySet("Value",((AnsiString)Query1->FieldByName("edad")->Value)/*.c_str()*/);
if(!Query1->FieldByName("sexo")->Value.IsNull())
v1.OlePropertyGet("Item",lnContador,4).OlePropertySet("Value",(/*(AnsiString)*/Query1->FieldByName("sexo")->Value)/*.c_str()*/);
lnContador++;
Query1->Next();
}
//this will stop asking you where you want to same your excel file or not
XL.OlePropertySet("DisplayAlerts",false);
//set the application as invisible, you can reverse “false" to “true" to make it visible
XL.OlePropertySet("Visible",true);
//save what you have done
// XL.OleProcedure("Save");
//quite the excel application
// XL.OleProcedure("Quit");
//unassign variable
XL=Unassigned;
}
Agradecería mucho la ayuda que puedas brindarme. |