//-------------------------------#include <vcl.h>
#pragma hdrstop
#include <ComObj.hpp>
#include 'xlauto2.h'
//-------------------------------#pragma package(smart_init)
#pragma resource '*.dfm'
TForm1 *Form1;
Variant XL,v0,v1,v2;
//Function Item('Item');
//---------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//-------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{
XL=CreateOleObject('Excel.Application.8');
XL.OlePropertySet('Visible',true);
v0=XL.OlePropertyGet('Workbooks');
v0.OleProcedure('Add');
v1=v0.OlePropertyGet('Item',1);
v0=v1.OlePropertyGet('Worksheets') ;
v0.OlePropertyGet('Item',1).OlePropertySet('Name','Бухгалтерия желтая');
v0.OlePropertyGet('Item',2).OlePropertySet('Name','Бухгалтерия красная');
for (int j=1;j<3;j++)
{
v1=v0.OlePropertyGet('Item',j);
for (int i=1;i<11;i++)
{
v1.OlePropertyGet('Cells').OlePropertyGet('Item',i,1).OlePropertySet('Value',i);
v1.OlePropertyGet('Cells').OlePropertyGet('Item',i,2).OlePropertySet('Value',i*5);
v2=v1.OlePropertyGet('Cells').OlePropertyGet('Item',i,2);
v2.OlePropertyGet('Font').OlePropertySet('Color',clBlue);
v2.OlePropertyGet('Font').OlePropertySet('Bold',true);
v2.OlePropertyGet('Interior').OlePropertySet('ColorIndex',9-3*j);
}
v1.OlePropertyGet('Cells').OlePropertyGet('Item',11,1).OlePropertySet('Value','=SUM(A1:A10)');
v1.OlePropertyGet('Cells').OlePropertyGet('Item',11,2).OlePropertySet('Value','=SUM(B1:B10)');
}
//отключить диагностику при закрытии сервера
XL.OlePropertySet('DisplayAlerts',false);
XL.OlePropertyGet('Workbooks').OlePropertyGet('Item',1).OleProcedure('SaveAs','test.xls');
XL.OleProcedure('Quit');
}
//-------------------------------