Hola de nuevo, despues ya de 3 dias intentando exportar a Excel como se hace en delphi sin nigun exito, al fin he encontrado la forma de hacerlo, aki os dejo un ejemplo
Código:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Variant Excel,Libro,Hoja,Celda;
Excel = CreateOleObject("Excel.Application");
Excel.OlePropertySet("Visible", true);
Libro=Excel.OlePropertyGet("Workbooks");
Libro.OleProcedure("Add");
Hoja=Libro.OlePropertyGet("Item",1);
Libro=Hoja.OlePropertyGet("Worksheets");
Libro.OlePropertyGet("Item",1).OlePropertySet("Name","The yellow book-keeping ");
Libro.OlePropertyGet("Item",2).OlePropertySet("Name","The red book-keeping ");
for (int j=1;j<3;j++)
{
Hoja=Libro.OlePropertyGet("Item",j);
for (int i=1;i<11;i++)
{
Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",i,1).OlePropertySet("Value",i);
Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",i,2).OlePropertySet("Value",i*5);
Celda=Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",i,2);
Celda.OlePropertyGet("Font").OlePropertySet("Color",clBlue);
Celda.OlePropertyGet("Font").OlePropertySet("Bold",true);
Celda.OlePropertyGet("Interior").OlePropertySet("ColorIndex",9-3*j);
}
Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",11,1).OlePropertySet("Value","=SUM(A1:A10)");
Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",11,2).OlePropertySet("Value","=SUM(B1:B10)");
}
Excel.OlePropertySet("DisplayAlerts",false); //suppress the warning dialog on closing the server
Excel.OlePropertyGet("Workbooks").OlePropertyGet("Item",1).OleProcedure("SaveAs","test.xls");
//Excel.OleProcedure("Quit");
Excel=Unassigned;
}
Salu2, espero que os sirva.