Build 4.0.0.67 of xlsgen makes it possible to add Form controls to spreadsheets.
Form controls in xlsgenAny of 11 form control types can be added :
- Buttons
- Check boxes
- Radio buttons
- Labels
- Edit boxes
- Spin controls
- Scroll bars
- List boxes
- Combo boxes
- Group boxes
- Dialog boxes
They can be added to XLS as well as XLSX/XLSM and XLSB files, so you do not have to worry about the underlying file format.
Each form control has a number of custom properties to it and xlsgen exposes
them. One of the most powerful ones is the ability to attach to it a VBA macro by its name.
Here is how to do add a button control and a list box (C++) :
// create a button and attach it an existing VBA macro
xlsgen::IXlsWorksheetPtr worksheet = workbook->AddWorksheet( L"sheet1" );
xlsgen::IXlsFormButtonPtr button = worksheet->FormControls->Buttons->Add(L"my button",2/*row1*/,2/*col1*/,5/*row2*/,6/*col2*/,0,0,0,0);
button->VBAMacro = L"=myButton_Click";
xlsgen::IXlsWorksheetPtr worksheet2 = workbook->AddWorksheet( L"sheet2" );
worksheet2->Label[2][7] = L"item1";
worksheet2->Label[3][7] = L"item2";
worksheet2->Label[4][7] = L"item3";
worksheet2->Label[5][7] = L"item4";
// create a list box and preselect two items
xlsgen::IXlsFormListBoxPtr listbox = worksheet2->FormControls->ListBoxes->Add(2,2,9,6,0,0,0,0);
listbox->SelectionType = xlsgen::listboxtype_multipleselection;
listbox->InputRange = L"=$G$2:$G$5";
listbox->SelectItem(3);
listbox->SelectItem(1);
listbox->LinkedCell = L"=$G$10";