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
K2 Automated Testing Software
BenchQA allows full test automation of K2, including fully automated K2 SmartForms and K2 Workflow testing. It promotes test driven development for K2 and ensures continued quality assurance for K2 solutions. Easily apply changes to test cases to accommodate changes to K2 apps and ensure all apps are regression tested to avoid defects and assure continuous quality.
First, extract the folder and copy the Excel export DLL from bin folder
(DLL Location: 20130814 Excel Controls v1.01 for community20140305 ExcelExportv1.01 Working.zipExcelExportbinDebug)
- Manually copy ExcelExport.dll file to the following directories:
- K2 Designer server: C:Program Files (x86)K2 blackpearlK2 SmartForms DesignerBin
- K2 SmartForms Runtime server: C:Program Files (x86)K2 blackpearlK2 SmartForms RuntimeBin
- Register the control using controlutil.exe
- The controlutil.exe can be found in C:Program Files (x86)K2 blackpearlBin
- Syntax:
controlutil.exe register -assembly:”C:Program Files (x86)K2 blackpearlK2 SmartForms DesignerbinExcelExport.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.
ADO Query
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