15. OLE

Печать
Рейтинг пользователей: / 1
ХудшийЛучший 

OLE

?????????? OLE

 

? ?????????? Microsoft Office ??? ?????? ? ????????? ???????????? ?????????? COM (Component Object Model - ????????? ?????? ???????????). ?? ????????? ?????????? COM ???????? ?????????? OLE Automation, ??????? ????????? ???????? ???? ?????????? ?? ???????, ?? ?????? ?? ????? ?????????? ???????? ?????????.

OLE (Object Linking and Embedding - ?????????? ? ????????? ????????) - ??? ?????, ??????????? ????????????? ?????? ?? ?????? ?????????? ? ?????? ??? ?????????? ?? ? ?????? ??????????. ????????, ????????? OLE ????? ????? ???????? ??????? Excel ? ???????? Word.

??????????? ????????????? OLE ??????????:

1.?????? ? ?????????? ????????? ?? ??????? ????????????????? ??????????;

2.???????? ???????????????? ???????, ????????? ????????????? ????? ?????????? ??? Word ? Excel;

3.?????????????? ???????? ??????????, ??????????????? ?? ???? ?????????;

4.?????? ? ??????????, ??????????? ? ??????.

? ?????????? OLE ???????????? ????? ??????? ??? OLE-????????? ? OLE-?????????. OLE-????????? ????? ????????? ???? ??? ????????? ??????????. ??? ??????????? ?????????? ????? ?????? ????.

??????? ????????????? ???????? ?? ??????? ?????????? ?????????? ??????????????.

?????????, ??????? ????????????? ???? ??????? ??? ????????????? ?? ??????? ???????????, ?????????? ????????? ?????????????. ?????????, ???????????? ????? ???????, ?????????? ?????????.

?????????? ????? ????????? - ??? ????, ??????? ???????? ???????? ????????? ?????? ?????????.

 


???? ?????? ???????

?????? ?????? ????? ??? ???? ??????: ?????? ????????????? (Presentation Data, PD) ? ???????????? ?????? (Native Data, ND). ?????? ????????????? ?????? ??? ????????????? ?????????? ???, ??? ??? ???????????? ? ???????????? ??????????. ????????, ??????? Excel ?????? ???? ???????????? ? ????????? ?????. ???????????? ?????? - ??? ??????????, ?.?. ?????????? ???????.

 

?????????? ? ????????? ????????

1.??????????

??? ?????????? ??????? ???????? ?????? ????????????? ? ?????? ?? ???????????? ??????. ? ???? ?????? ???????????? ?????? ???????? ?? ??????? ?????????, ? ?????? ????????????? - ? ????????-???????????.

2.?????????

??? ????????? ? ???????????? ??????, ? ?????? ????????????? ???????? ? ???????-??????????. ?????? ?????????? ??? ?????? ?????????? ? ?? ?????????? ? ???? ????????? ??????.

?????????? ???????? ?????????????

????? ??????? ?????? ?? ?????????? ?????, ??????????? ? ??????? ?????????????, ?????????? ??????? ????? ???? Project/Add Reference, ?? ??????? ??? ??????? ??????????? ?????????? ? ???????? ?? ? ?????? ????????? ???????????. ????????, ??? ?????? ? Microsoft Excel ?????????? ??????? ?????????? Microsoft Excel Object Library

??? ????????? ??????????? ? ????????, ???????? ? ??????????, ????? ??????????????? ????? ???????? ???????? (Object Browser). ? ????? ????? ???? ??????????? ??????? ? ??????????, ??????? ???????? ? ??????????, ? ?????? ????? - ????????, ??????? ? ?????? ?????????? ???????. ????? ???????????? ??????? ???????? ???????.

 

??????? ???????? ???? ???????? Microsoft Office ???????? ?????? Application.

 

??? ????????? ??????? ? ???????? ???????????? ??????? CreateObject. ?????????? ??? ???????? ????????????? ???? ???????.

1.?????? ?????????? (early binding): ??????????? ??????????, ??????? ????? ????????? ??????????????? ??????, ? ????? ?????????? ??????? CreateObject. ? ???? ?????? ????? ? ??????????? ????? ??????????????? ?? ?????? ??????????.

Dim MyExcel As Excel.Application

MyExcel=CreateObject(Excel.Application)

??? Excel - ??? ?????? ?? ?????? ?????????????, a Application - ?????? ?? ??????, ?????????????? ???????? ?????????????. ????? ???????, ??? ?????? ????? ????????? ??????? Application ??????? ?????????????.

??? ?????, Dim MyExcel As New Excel.Application

2.??????? ??????????? (late binding): ??????????? ?????????? ???? Object.

Dim MyExcel As Object

MyExcel=CreateObject(Excel.Application)

?????? ?????? ????? ?????? ??? ???????, ? ??????, ???? ?????????? ???????????, ????????, ?? ????????? ???????, ??? ??????????? ?????? ?????? Microsoft Office.

 

????? ???? ??? ?????? ??????, ? ??? ????? ????????. ??? ????? ?????? ?????????? ???? ???????? ?????????? ???????.

??? ?????? ??????? CreateObject ?????????? ????? ?????????, ?? ?? ????? ????????????. ??? ???? ????? ????????? ????? ????????, ??????? ????????? ?????????, ???????? ?????? ????????? ? ??????? ??????????.

??? ???? ????? ?????????? ???????????? ?? ?????? ?????????? ???????????? ???????? Visible. ????????, MyExcel.Visible=True.

 

? ??????????? Microsoft Office ????? ???????????? ????????? ???????:

1.Workbooks, ????????? ???????? ?????????????? ????? ??????? ???? Excel.

2.Worksheets, ????????? ???????? ?????????????? ????? ?????? Excel.

3.Documents, ????????? ???????? ?????????????? ????? ?????????? Word.

??? ???????? ?????? ????? ???????????? ????? Add ???????.

????????, MyExcel.Workbooks.Add() ??? MyWord.Documents.Add()

 

? ????? ?????? ? ??????????? ??????? ????????????? ??? ?????????? ???????:

????????, MyExcel=Nothing ??? MyWord=Nothing

 


?????? ? Microsoft Excel

??? ?????? ? ???????? ???????????? ?????? ActiveCell.

??? ???????? ? ?????? ???????????? ????? Select ??????? Range (????????).

MyExcel.Range(A1).Select()

????? ????????? ???????? ?????? ?????????? ???????????? ???????? FormulaR1C1.

MyExcel.ActiveCell.FormulaR1C1 = 3

??? ?????? ??????? ???????????? ????????????? ?????? ?? ??????. ????????, R[1]C[-1] ????????, ??? ????? ????? ?????????? ??????, ??????????? ?? ???? ?????? ???? ? ???? ??????? ?????, ??? ???????? ??????. ??????? ?????? ?????????? ?? ????? ?????????.

????? ???????? ?????????? ?????? ??????? ? ?????? ???????

MyExcel.Selection.Font.Color =RGB(255,0,0)

MyExcel.Selection.Font.Bold =True

 


?????? ? Microsoft Word

??? ?????? ? ??????? ????? ???????????? ????????? Words, Sentences ? Paragraphs.

???? ??????:

MyWord.Selection.TypeText Hello World

?????????? ??????

MyWord.ActiveDocument.Range.InsertAfter(???????? ?????????: + MyWord.ActiveDocument.FullName + ??????? ???????????!!!)