|
Office Add-in Express. Как сделать...
AddIn_Initialize:
- Как получить доступ к CommandBar
- Как создать CommandBar
- Как задать позицию для нового CommandBar
- Как создать CommandBarEdit
- Как создать CommandBarEdit с подписью
- Как задать текст для CommandBarEdit
- Как изменить ширину CommandBarEdit
- Как создать CommandBarCombobox
- Как создать новую группу
- Как заполнить CommandBarCombobox
- Как создать CommandBarDropdown
- Как проинициализировать CommandBarDropdown
- Как отделить значения в CommandBarCombobox
- Как изменить ширину выпадающей части CommandBarCombobox
- Как создать CommandBarButton
- Как установить икноку и текст в CommandBarButton
- Как создать новую группу в CommandBar
- Как вставить CommandBarControl перед другим CommandBarControl
- Как создать CommandBarPopup
- Как добавить CommandBarControl в CommandBarPopup
- Как добавить пункт меню в стандартное меню
- Как добавить CommandBarControl на стандартный CommandBar
- Как добавить свое подменю в главное меню Excel
- Как добавить кнопку в главное меню Excel
AddIn_ControlEvent:
- Как создать обработчик событий для CommandBarEdit
- Как создать обработчик событий для CommandBarCombobox
- Как создать обработчик событий для CommandBarButton
- Как выставить состояние CommandBarButton
- Как найти CommandBarControl
- Как отключить CommandBarControl
- Как скрыть/показать CommandBar
- Как установить/снять защиту CommandBar
- Как отключить все CommandBarControls на данном CommandBar
AddIn_Initialize:
1. Как получить доступ к CommandBar
var IStdBar: IaxpCmdBar;
...
IStdBar := FIXL.CommandBars.Item['Standard'];
2. Как создать CommandBar
AddCmdBar(CmdBarBtns2, NewCtrl);
3. Как задать позицию для нового CommandBar
AddCmdBar(CmdBarEdits, NewCtrl, msoBarTop);
AddCmdBar(CmdBarBtns1, NewCtrl, msoBarLeft);
4. Как создать CommandBarEdit
AddEdit(CmdBarEdits, 'Edit1', Edt01Tag, 'This is an edit control', msoComboNormal, NewCtrl);
5. Как создать CommandBarEdit с подписью
var
IEdt: IaxpEdit;
...
IEdt := AddEdit(CmdBarEdits, 'Edit2:', Edt02Tag, 'This is an edit control', msoComboLabel, NewCtrl);
6. Как задать текст для CommandBarEdit
if NewCtrl then
IEdt.Text := 'abc';
7. Как изменить ширину CommandBarEdit
if NewCtrl then
IEdt.Width := 150;
8. Как создать CommandBarCombobox
var
ICBox: IaxpComboBox;
...
ICBox := AddComboBox(CmdBarEdits, 'Combo1', CBox01Tag, 'This is a combobox', msoComboNormal, false, NewCtrl);
9. Как создать новую группу
if NewCtrl then
ICBox.BeginGroup := true;
10. Как заполнить CommandBarCombobox
if NewCtrl then begin
ICBox.AddItem('First', EmptyParam);
ICBox.AddItem('Second', EmptyParam);
ICBox.AddItem('Third', EmptyParam);
ICBox.AddItem('Fourth', EmptyParam);
end;
11. Как заполнить CommandBarCombobox
ICBox := AddComboBox(CmdBarEdits, 'Combo2', CBox02Tag, 'This is a dropdown control', msoComboLabel, true, NewCtrl);
if NewCtrl then begin
ICBox.AddItem('First', EmptyParam);
ICBox.AddItem('Second', EmptyParam);
ICBox.AddItem('Third', EmptyParam);
ICBox.AddItem('Fourth', EmptyParam);
end;
12. Как проинициализировать CommandBarDropdown
if NewCtrl then
ICBox.ListIndex := 1;
13. Как отделить значения в CommandBarCombobox
if NewCtrl then
ICBox.ListHeaderCount := 2;
14. Как изменить ширину выпадающей части CommandBarCombobox
ICBox.DropDownWidth := 150;
15. Как создать CommandBarButton
AddButton(CmdBarBtns1, 'Click me', Btn01Tag, 'This is a standard button', '', msoButtonCaption, NewCtrl);
16. Как установить икноку и текст в CommandBarButton
var
IBtn: IaxpButton;
...
IBtn := AddButton(CmdBarBtns1, 'Fix me', Btn02Tag, 'This is a button with fixed state', 'ADDINXP', msoButtonIconAndCaption, NewCtrl);
Примечание: строка 'ADDINXP' это имя bitmap-ресурса.
17. Как создать новую группу в CommandBar
IBtn.BeginGroup := true;
18. Как вставить CommandBarControl перед другим CommandBarControl
AddButton(CmdBarBtns1, 'Show/Hide BigButtons', Btn04Tag, 'Show/Hide BigButtons commandbar', '', msoButtonCaption, NewCtrl, 3);
19. Как создать CommandBarPopup
var
IPopup: IaxpPopup;
...
IPopup := AddPopup(CmdBarBtns1, 'Pop-up', Popup01Tag, 'This is a pop-up control', NewCtrl);
20. Как добавить CommandBarControl в CommandBarPopup
// Button
AddButton(CmdBarBtns1, 'Button7', Btn07Tag, 'This is a button', 'ADDINXP', msoButtonIconAndCaption, NewCtrl, -1, IPopup);
// Edit
AddEdit(CmdBarBtns1, 'Edit', Edt03Tag, 'This is an edit control',
msoComboLabel, NewCtrl, -1, IPopup);
21. Как добавить пункт меню в стандартное меню
var
IPopup: IaxpPopup;
MenuName: string;
...
MenuName := 'File'; // Warning! Depends on localization.
IDispatch(IPopup) := OLEVariant(CmdBars.ActiveMenuBar).Controls.Item[MenuName];
AddButton(MenuName, 'MyItem', 'MyItemTag', 'This is a my menu item', 'ADDINXP', msoButtonIconAndCaption, NewCtrl, MyPosition, IPopup);
22. Как добавить CommandBarControl на стандартный CommandBar
var
BarName: string;
...
BarName := 'Standard'; // Warning! Depends on localization.
AddButton(BarName, 'MyButton', 'MyButtonTag',
'My button hint', 'MyButtonBitmatResourceName', msoButtonIcon, NewCtrl, 1);
23. Как добавить свое подменю в основное меню Excel
procedure TMyAddIn.AddIn_Initialize;
var
IPopup: IaxpPopup;
IsNew: boolean;
begin
inherited;
// Warning! The 'Worksheet Menu Bar' string is
// the Excel's menubar name and depends on
// localization. You can get the menubar name
// through CmdBars.Item[0].NameLocal
IPopup := AddPopup('Worksheet Menu Bar', 'My submenu',
'ADXHT001', '', IsNew, 5);
AddButton('Worksheet Menu Bar', 'Item 1',
'ADXHT001-01', '', '', msoButtonCaption, IsNew,
-1, IPopup);
AddButton('Worksheet Menu Bar', 'Item 2',
'ADXHT001-02', '', '', msoButtonCaption,
IsNew, -1, IPopup);
end;
24. Как добавить кнопку в основное меню Excel
procedure TADXHT001.AddIn_Initialize;
var
IPopup: IaxpPopup;
IsNew: boolean;
begin
inherited;
// Warning! The 'Worksheet Menu Bar' string is
// the Excel's menubar name and depends on
// localization. You can get the menubar name
// through CmdBars.Item[0].NameLocal
AddButton('Worksheet Menu Bar', 'My Button',
'ADXHT002', '', '', msoButtonCaption, IsNew, 6);
end;
AddIn_ControlEvent:
1. Как создать обработчик событий для CommandBarEdit
if Tag = Edit1Tag then
ShowMessage(Format('Ooops... I am the %s edit control.'#13'My new value is %s.',
[Tag, (ICtrl as IaxpEdit).Text]));
2. Как создать обработчик событий для CommandBarCombobox
if Tag = CBox01Tag then
ShowMessage(Format('Hm... I am the %s combobox.'#13'My new value is %s.',
[Tag, (ICtrl as IaxpComboBox).Text]));
3. Как создать обработчик событий для CommandBarButton
if Tag = Btn01Tag then
ShowMessage(Format('Hm... I am the %s button.', [Tag]));
4. Как выставить состояние CommandBarButton
if Tag = Btn02Tag then begin
IBtn := ICtrl as IaxpButton;
if IBtn.State = msoButtonUp then
IBtn.State := TOLEEnum(msoButtonDown)
else
IBtn.State := TOLEEnum(msoButtonUp);
end;
5. Как найти CommandBarControl
var
IEdt: IaxpEdit;
...
IEdt := FindControl(CmdBarEdits, Edt01Tag, axpEdit) as IaxpEdit;
6. Как отключить CommandBarControl
if Tag = Btn03Tag then
if Assigned(IEdt) then
IEdt.Enabled := not IEdt.Enabled;
7. Как скрыть/показать CommandBar
if Tag = Btn04Tag then
CmdBars.Item['MyBar'].Visible := not CmdBars.Item['MyBar'].Visible;
8. Как установить/снять защиту CommandBar
if Tag = Btn05Tag then
if CmdBars.Item['MyBar'].Protection = msoBarNoProtection then
CmdBars.Item['MyBar'].Protection :=
msoBarNoResize + msoBarNoMove + msoBarNoChangeVisible
else
CmdBars.Item['MyBar'].Protection := msoBarNoProtection;
9. Как отключить все CommandBarControls на данном CommandBar
if Tag = Btn06Tag then
for i := 1 to CmdBars.Item['MyBar'].Controls_.Count do
CmdBars.Item['MyBar'].Controls_.Item[i].Enabled :=
not CmdBars.Item['MyBar'].Controls_.Item[i].Enabled;
Обзор Quick Demo Загрузить
|