RE:crear fichero excel desde c++ builder
Te dejo 2 ejemplos, espero que se sirvan para algo... aunque sea para ver
por donde atacar el problema...
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;
}
Otro ejemplo:
Variant Ex,Wb,Sh1;
Ex = Variant::CreateObject("Excel.Application");
Ex.PG("WorkBooks").PR("Open", "c:\\book1.xls");
Wb = Ex.PG("ActiveWorkBook");
Sh1 = Wb.PG("ActiveSheet");
Edit1->Text = Sh1.PG("Cells", 1, 1).PG("Value");
for(int i=1; i<=10; i++)
for(int j=1; j<=10; j++)
Sh1.PG("Cells", i, j).PS("Value", i*100 + j);
Saludos desde Baires, JuanC