How to register and use the Excel Control for K2 SmartForms
K2 Smartforms Export to Excel
In this article, we will learn about how to export the SmartObject data to an Excel spreadsheet using the K2 Excel custom control
The Excel control can be downloaded from here.
How to register the Excel Control
Before using the control, you need to register it to make it available in K2 SmartForm designer
First, extract the folder and copy the Excel export DLL from bin folder
(DLL Location: 20130814 Excel Controls v1.01 for community\20140305 ExcelExportv1.01 Working.zip\ExcelExport\bin\Debug)
- Manually copy ExcelExport.dll file to the following directories:
- K2 Designer server: C:\Program Files (x86)\K2 blackpearl\K2 SmartForms Designer\Bin\
- K2 SmartForms Runtime server: C:\Program Files (x86)\K2 blackpearl\K2 SmartForms Runtime\Bin\
- Register the control using controlutil.exe
- The controlutil.exe can be found in C:\Program Files (x86)\K2 blackpearl\Bin
controlutil.exe register -assembly:”C:\Program Files (x86)\K2 blackpearl\K2 SmartForms Designer\bin\ExcelExport.dll”
Deploy the ExcelFile SmartObject
From Project Folder, open the ExcelSmartObjects Solution and deploy the ExcelFile SmartObject.
This SmartObject is used to store the generated Excel file in K2 SmartBox SQL Server database
After registering the control, you should be able to see the Excel export control in the K2 SmartForm designer under Excel controls section
How to use the Excel control in K2 list view control
Drag the controls below onto a new K2 listview –
- Toolbar button
- File Attachment
- Excel control
Generating an Excel File
Under Toolbar button click event
Add an action called Execute a view control method
Select control as Excel export and it has only one method “Create Excel File”
Now, configure the Excel export control by passing the ADO query as input parameter on SmartObject data.
For Ex: SELECT Name,Country,Age,Email,Mobile FROM Employees Having Country=’United Kingdom’
The control will extract the data based on input query and stores the generated file into K2 SmartBox and returns the file ID as parameter.
Now, execute Excel file SmartObject load method by passing a file id as input value. The SmartObject will subsequently return a file. Ensure to map the return value to file attachment control in the view.
By clicking on the file attachment control, you can download the generated Excel file with extracted data from SmartForm listview