#include <vcl.h>
#include <ComObj.hpp> // Para OLE Automation
#pragma hdrstop
void __fastcall TForm1::ButtonOpenClick(TObject *Sender)
{
// Obtener la ruta del archivo desde el TEdit
String filePath = EditFilePath->Text;
// Crear una instancia de Excel
OleVariant excelApp = CreateOleObject("Excel.Application");
excelApp.OleProperty["Visible"] = false; // No mostrar Excel
// Abrir el archivo de Excel
OleVariant workbook = excelApp.OleFunction("Workbooks.Open", filePath);
OleVariant sheet = workbook.OleProperty["Worksheets"][1]; // Obtener la primera hoja
// Leer datos de la hoja
for (int row = 1; row <= 10; row++) // Cambia el rango según tus necesidades
{
for (int col = 1; col <= 5; col++) // Cambia el rango según tus necesidades
{
OleVariant cellValue = sheet.OleProperty["Cells"][row][col];
MemoData->Lines->Add(cellValue); // Agregar el valor al TMemo
}
}
// Cerrar el libro y la aplicación
workbook.OleProcedure("Close", false);
excelApp.OleProcedure("Quit");
}