//-------------------------------#include <vcl.h>
#pragma hdrstop
#include 'ole2.h'
#include <ComObj.hpp>
//-------------------------------#pragma package(smart_init)
#pragma resource '*.dfm'
TForm1 *Form1;
Variant XL,v0,v1,v2, v22, vrange, WD,a,b,c;
//-------------------------------__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') ;
v22=v1.OlePropertyGet('Charts') ;
v22.OleProcedure('Add');
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)');
}
vrange=v0.OlePropertyGet('Item',1).OlePropertyGet('Range','A1:A10");
v1=v22.OlePropertyGet('Item',1);
v2=v1.OlePropertyGet('SeriesCollection');
v2.OleProcedure('Add',vrange);
vrange=v0.OlePropertyGet('Item',1).OlePropertyGet('Range','B1:B10");
v2.OleProcedure('Add',vrange);
v1.OleProcedure('Select');
XL.OlePropertyGet('Selection').OleProcedure('Copy');
WD=CreateOleObject('Word.Application.8');
WD.OlePropertySet('Visible',true);
WD.OlePropertyGet('Documents').OleProcedure('Add');
a=WD.OlePropertyGet('Documents');
b=a.OleFunction('Item',1);
for (int i=1;i<5;i++)
{b.OlePropertyGet('Paragraphs').OleProcedure('Add');};
c=b.OleFunction('Range',1,2);
c.OleProcedure('Paste');
c=b.OleFunction('Range',3,3);
c.OlePropertySet('Text','График, скопированный из рабочей книги Excel ');
XL.OlePropertySet('DisplayAlerts',false);
XL.OlePropertyGet('Workbooks').OlePropertyGet('Item',1).OleProcedure('SaveAs','test.xls');
XL.OleProcedure('Quit');
WD.OlePropertySet('DisplayAlerts',false); b.OleProcedure('SaveAs','test2.DOC');
WD.OleProcedure('Quit');
}
//-------------------------------