COMO INTERACTUAR CON EXCEL

tato
20 de Julio del 2003
Hola, espero que alguien me ayude, tengo que cargar una hoja de excel como parte de un formulario en c++ builder, como puedo hacer??????????
Tambien tengo que guardar los cambios que haga a la hoja desde c++.
Espero me contesten pronto......., de esto depende mi empleo

victor ya?
20 de Julio del 2003
Hay que añadir #include <Comobj.hpp> para BCB3, 4 y 5 o bien #include <oleauto.hpp> para BCB1

//-------- Abre EXCEL
Variant xlApp;
xlApp = CreateOleObject("Excel.Application");

//-------- hace EXCEL visible
xlApp.Exec(PropertySet("Visible") << true);

//-------- crea acceso al objeto 'libro'/workbook
Variant xlBooks = xlApp.Exec(PropertyGet("Workbooks"));

//-------- Crea un fichero nuevo
xlBooks.Exec(Procedure("Add"));
// ... o abre uno existente
// xlBooks.Exec(Procedure("Open") << "C:\directorio\fichero.xls");

//-------- coge el primer libro de la aplicacion
Variant xlBook = xlBooks.Exec(PropertyGet("Item") << 1);

//-------- crea acceso al objeto 'hoja'/worksheets
Variant xlSheets = xlBook.Exec(PropertyGet("Worksheets"));

//-------- coge la primera hoja del libro
Variant xlSheet = xlSheets.Exec(PropertyGet("Item") << 1);

//-------- Trabajando con celdas...
Variant VRange;
//-------- Escribe texto en las primeras 3x3 celdas
VRange = xlSheet.Exec(PropertyGet("Range") << "A1");
VRange.Exec(PropertySet("Value") << "CeldaA1");
VRange = xlSheet.Exec(PropertyGet("Range") << "A2");
VRange.Exec(PropertySet("Value") << "CeldaA2");
VRange = xlSheet.Exec(PropertyGet("Range") << "A3");
VRange.Exec(PropertySet("Value") << "CeldaA3");
//------
VRange = xlSheet.Exec(PropertyGet("Range") << "B1");
VRange.Exec(PropertySet("Value") << "CeldaB1");
VRange = xlSheet.Exec(PropertyGet("Range") << "B2");
VRange.Exec(PropertySet("Value") << "CeldaB2");
VRange = xlSheet.Exec(PropertyGet("Range") << "B3");
VRange.Exec(PropertySet("Value") << "CeldaB3");
//------
VRange = xlSheet.Exec(PropertyGet("Range") << "C1");
VRange.Exec(PropertySet("Value") << "CeldaC1");
VRange = xlSheet.Exec(PropertyGet("Range") << "C2");
VRange.Exec(PropertySet("Value") << "CeldaC2");
VRange = xlSheet.Exec(PropertyGet("Range") << "C3");
VRange.Exec(PropertySet("Value") << "CeldaC3");

//-------- Borra las primeras 2 x 2 celdas
VRange = xlSheet.Exec(PropertyGet("Range") << "A1:B2");
VRange.Exec(Function("ClearContents"));

//-------- Guarda el libro actual
xlBook.Exec(Procedure("SaveAs") << "c:\fichero.xls");

//-------- Cierra excel
xlApp.Exec(PropertySet("Visible") << false);
xlApp.Exec(Procedure("Quit"));
xlApp.Clear();

//Encontre esto, espero te sirva ;-)