#include <stdio.h>
#include <comobj.hpp>
//----------------------------------- /*
********************************************************************
* EXCEL READ VALUE FUNCTION *
* http://demenev.ucoz.ru *
* Demenev Alexandr *
* (>_(>_(>_(0_0)_<)_<)_<) *
********************************************************************
* Edit1->Text=ExclelRead(FILENAME,LIST,BOOK,VISIBLE,STROKA,STOLB); *
* ******************************************************************
*/
String ExcelRead(String ExcelFile,int ExcelList,int ExcelBook,int ExcelVisible,int ExcelStroka,int ExcelStolb)
{
String ExcelText;
//_______________________________
static char cellText[256] ;
cellText[0] = 'A' + ExcelStolb ;
sprintf(&cellText[1],"%d",ExcelStroka+1);
//_______________________________
Variant app;
Variant books ;
Variant book;
Variant sheet ;
app = CreateOleObject("Excel.Application");
books = app.OlePropertyGet("Workbooks");
books.Exec(Procedure("Open")<<ExcelFile);
book = books.OlePropertyGet("item",ExcelBook);
sheet= book.OlePropertyGet("WorkSheets",ExcelList);
app.OlePropertySet("Visible", ExcelVisible); //0 - Visible false, 1-Visible true
ExcelText=sheet.OlePropertyGet("Range", cellText ); //0 - stroka, 0 - stolb
app.OleFunction("Quit");
app= Unassigned;
return ExcelText;
}
//***************************************************************************
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Edit1->Text=ExcelRead("C:\\1.xls",1,1,0,0,0);
}