Introducing nexacro-xeni
Nexacro provides nexacro-xeni for export and import processing of Excel. nexacro-xeni is a server application that performs the function of returning the result after processing the export/import of Excel on the server.
The reason that the Excel export/import function is not processed by itself and is cumbersome through the server application is that the resources of the local system must be used to process the Excel file. This can pose a serious security issue, so your browser is blocking it. Therefore, Nexacro provides the method using nexacro-xeni.
nexacro-xeni is written based on Apache POI. Therefore, it is possible for you to use Apache POI, but we do not take any responsibility for any problems caused by it. Please refer to https://poi.apache.org/ for a detailed explanation.
nexacro-xeni can export/import the following documents.
File Type | Extension | Description |
---|---|---|
Microsoft Excel 97-2003 | xls | Supports both export / import |
Microsoft Excel 2007/2010 | xlsx | Supports both export / import |
CSV format file | csv | Supports only import |
HancomOffice Hancell 2010 / 2014 | cell | Support in plan |
When exporting/importing, files are created on the server. These files are managed through the file manager of nexacro-xeni, so the developer does not need to worry about using them as default settings. The file manager can configure the operation through the servlet context parameter in the /WEB-INF/web.xml file of the server. The following describes the elements that can be set as servlet context parameters.
Name | Default Value | Description |
---|---|---|
export-path | /export | Specify the path to temporarily save the downloaded file. |
import-path | /import | Specifies the path to temporarily save the files to be imported into the grid component. If the monitor-enabled setting is true, data is deleted immediately after processing. |
monitor-enabled | true | Specifies whether to run the file manager. If specified to false, the file manager does not operate and temporary files are not deleted. |
monitor-cycle-time | 30 | Sets the interval for deleting temporarily stored download files in 'minutes'. Runs the file manager at an appropriate interval to check and delete files to be deleted. |
file-storage-time | 10 | Sets the interval for deleting temporarily stored download files in 'minutes'. When the file manager is executed, files that have transmitted the specified time since creation are deleted. |
For more information, please refer to the README.txt file included in the deployed nexacro-xeni.war file.
Introducing ExcelExportObject
ExcelExportObject is the object used to export the contents of Grid to an Excel file. The developer can use this object to make the necessary settings for export and make requests to the server.
The result of export processing can be checked through the event. Events that can be used include onsuccess, onerror, and onprogress. onsuccess is the event that occurs when export is successfully completed, and onerror is the event that occurs when an error occurs during export. onprogress is the event that occurs according to the export progress. Events can be used by registering events and event handlers when creating the object.
ExcelExportObject is a shapeless object, unlike other UI components. Therefore, you need to create objects and events directly by the script. The following is a brief description and sample of the procedure for performing the export using ExcelExportObject.
1
Creating Object
Create the ExcelExportObject object.
this.exportObj = new ExcelExportObject("Export00", this);
2
Setting Properties
Set the name of the Excel file to be saved, the URL of the service performing the export, and Grid and range to be targeted, as necessary.
this.exportObj.set_exportfilename("ExcelExportFile"); this.exportObj.set_exporttype(nexacro.ExportTypes.EXCEL2007); this.exportObj.set_exporturl("http://localhost:8080/XExportImport");
3
Adding Component to Export
this.exportObj.addExportItem(nexacro.ExportItemTypes.GRID, this.Grid00, "Sheet1!A1");
4
Registering Event Handler
If necessary, register events and event handlers using the addEventHandler method. You must implement the event handler registered here.
this.addEventHandler("onsuccess", this.Export00_onsuccess, this); this.addEventHandler("onerror", this.Export00_onerror, this);
5
Performing Export
Perform export when everything is ready.
this.exportObj.exportData();
Introducing ExcelImportObject
ExcelImportObject is the object used to import the contents of an Excel file to Grid. It is responsible for settings required for import and requests to the server. The developer can use it in scripts to import Excel.
The result of the import process can be checked through the event. Events that can be used include onsuccess and onerror. onsuccess is the event that occurs when the import is successfully completed, and onerror is the event that occurs when an error occurs during import. Events can be used by registering events and handlers when creating the object.
1
Creating Object
Create the ExcelImportObject object.
this.importObj = new ExcelImportObject("Import00", this);
2
Setting Properties
Set the format of the file to be imported and the URL of the service that performs the import, as necessary.
this.importObj.set_importtype(nexacro.ImportTypes.EXCEL); this.importObj.set_importurl("http://localhost:8080/deploy/XImport");
3
Registering Event Handler
If necessary, register events and event handlers using the addEventHandler method. You must implement the event handler registered here.
this.importObj.addEventHandler("onsuccess", this.Import00_onsuccess, this); this.importObj.addEventHandler("onerror", this.Import00_onerror, this);
4
Execution
Perform import when everything is ready.
this.importObj.importData("", "Sheet1!A1:F6", "Dataset00");
Exporting Grid as Excel File (Export)
You can export Grid on the screen as an Excel file using ExcelExportObject.
Example
The following is an example of downloading the contents of Grid as an Excel file using ExcelExportObject.
Clicking the Export button creates the ExcelExportObject object, sets the properties required for export, and then exports. When the export is performed, a file download dialog appears and you can save it to the local PC.
sample_excelexportimport_01.xfdl
The following shows the contents of the Excel file saved on the local PC after exporting. You can see that the Grid data is exported as an Excel file.
Core features used in the example
- exportfilename
This is the property that sets the file name to be saved after the export is completed. If this property is not set, it is set to an arbitrary file name.
- exporturl
This is the property that sets the URL of the service to be exported. If this property is not set, then no export is performed.
- addExportItem
This is the method that adds the item (component) to be exported to the export list of ExcelExportObject. Currently, only Grid is supported.
- addEventHandler
This is the method that adds the event handler to be executed when the event occurs.
- exportData
This is the method that exports the items added to the ExcelExportObject.
- importData
This is the method that adds the event handler to be executed when the event occurs.
How to implement an example
This sample was created to run on demo.nexacro.com. To perform the sample on the user PC, WAS and nexacro-xeni must be installed and running. Also, you need to modify the url related settings in the sample script code to suit your environment. If the domains of the WAS and the user PC are different, cross-domain problems may occur.
1
Creating Component
Select the button and the grid from the toolbar, and drag it to an appropriate size on Form to create it. If you just click on the form, it will be created with the default size.
2
Creating Dataset and Entering Data
Create Dataset with the data item list to be displayed on Grid.
Select Dataset from the toolbar and click on an appropriate space on the form to create Dataset.
Enter the data item list in the created Dataset. If you double-click Dataset in the Invisible Objects area, the Dataset Editor appears. Enter Columns and Rows as shown in the figure below.
3
Dataset Binding
Bind Dataset to the Grid component.
Binding is completed by dragging and dropping Dataset in the Invisible Objects area to the Grid component created on Form.
4
Implementing Export Function
Select Button in Form and add the onclick event handler as shown below.
this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo) { this.exportObj = new ExcelExportObject("Export00", this); this.exportObj.set_exportfilename("ExcelExportFile"); this.exportObj.set_exporturl("http://demo.nexacro.com/developer_guide/XExportImport"); this.exportObj.addExportItem(nexacro.ExportItemTypes.GRID, this.Grid00, "Sheet1!A1"); this.addEventHandler("onsuccess", this.Export00_onsuccess, this); this.addEventHandler("onerror", this.Export00_onerror, this); var intExportedItem = this.exportObj.exportData(); trace("Number of Exported Item: " + intExportedItem); };
5
Implementing Event Handler
this.Export00_onsuccess = function(obj:ExcelExportObject, e:nexacro.ExcelExportEventInfo) { trace("Export00_onsuccess"); } this.Export00_onerror = function(obj:ExcelExportObject, e:nexacro.ExcelExportEventInfo) { trace("Export00_onerror"); }
6
Checking with QuickView
Run it with QuickView (Ctrl + F6).
Click the Export button to check whether the data is exported as an Excel file in Grid of the screen.
Reading Excel File to Show on Grid (Import)
ExcelImportObject can be used to import an Excel file in the local PC into Grid on the screen.
Example
The following is an example of importing an Excel file from the local PC to Grid on the screen using ExcelImportObject.
Clicking the Import button creates the ExcelImportObject object, sets the properties required for import, and then imports. When the import is performed, a file open dialog appears and you can select an Excel file on the local PC. During the import process, an image notifying the progress is displayed. At that time, pressing the ESCkey stops the import.
sample_excelexportimport_02.xfdl
The following is the Excel file of the local PC used when performing the import. You can see that there is a difference between the data of the Excel file and the data of the imported Grid because the range of cells is set to A1 to E7 when importing.
Since this sample is designed to show the function, an error may occur when importing Excel with a complex structure.
Core features used in the example
- importtype
This is the property that sets the format of the file to be imported. The setting can be made with the constant values in the following table. Hancell 2010 format is not currently supported, so please convert it to Excel 2007 file before use.
nexacro.ImportTypes.EXCEL | Imports in Excel 97 format. |
---|---|
nexacro.ImportTypes.EXCEL97 | Imports in Excel 97 to 2003 format. |
nexacro.ImportTypes.EXCEL2007 | Imports in Excel 2007 format. |
nexacro.ImportTypes.HANCELL2014 | Imports in Hancell 2014 format. |
- importurl
This is the property that sets the URL of the service to be imported. If this property is not set, no import is performed.
- addEventHandler
This is the method that adds the event handler to be executed when the event occurs.
- importData
This is the method that imports Excel or Hancell file into Dataset.
this.ExcelImportObject00.importData("http://localhost:8080/xeni/XImport/my.xlsx","Sheet00!D15:E28","Dataset03=output1"); this.ExcelImportObject00.importData("","Sheet00!D15:E28","Dataset03=output1","filepassword=strpassword"); this.ExcelImportObject00.importData("", "[Command=getsheetlist;Output=sheetlist][Command=getsheetdata;Output=output1;Head=!A1:K1;Body=!A2:K15][Output=output2; Body=Sheet1!B7:Z207]", "ds_list=sheetlist, ds_Data1=output1, ds_Data2=output2");
How to implement an example
This sample was created to run on demo.nexacro.com. To perform the sample on the user PC, WAS and nexacro-xeni must be installed and running. Also, you need to modify the url related settings in the sample script code to suit your environment. If the domains of the WAS and the user PC are different, cross-domain problems may occur.
1
Creating Component
Select the button and the grid from the toolbar, and drag it to an appropriate size on Form to create it. If you just click on the form, it will be created with the default size.
2
Implementing Import Function
Select Button in Form and add the onclick event handler as shown below.
this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo) { this.importObj = new ExcelImportObject("Import00", this); this.importObj.set_importtype(nexacro.ImportTypes.EXCEL); this.importObj.set_importurl("http://demo.nexacro.com/developer_guide/XImport"); this.importObj.addEventHandler("onsuccess", this.Import00_onsuccess, this); this.importObj.addEventHandler("onerror", this.Import00_onerror, this); this.importObj.importData("", "Sheet1!A1:E7", "Dataset00"); };
3
Implementing Event Handler
this.Import00_onsuccess = function(obj:ExcelImportObject, e:nexacro.ExcelImportEventInfo) { trace("Import00_onsuccess"); this.Grid00.createFormat(); } this.Import00_onerror = function(obj:ExcelImportObject, e:nexacro.ExcelImportErrorEventInfo) { trace("Import00_onerror"); }
4
Checking with QuickView
Run it with QuickView (Ctrl + F6).
When you click the Import button, a file dialog window appears. When you select an Excel file, the import is in progress, and check whether the Excel contents are imported into Grid on the screen.
Exporting Grid Image as Excel File
You can export Grid on the screen as an Excel file using ExcelExportObject. At this time, if there is an image included in Grid, the image can also be exported using the exportimage property of the ExportItem object.
Example
The following is an example of downloading the contents of Grid as an Excel file using ExcelExportObject.
Clicking the Export image button creates the ExcelExportObject object, sets the properties required for export, and then exports. When the export is performed, a file download dialog appears and you can save it to the local PC.
sample_excelexportimport_03.xfdl
The following shows the contents of the Excel file saved on the local PC after exporting. You can see that the Grid data and image are exported as an Excel file.
Core features used in the example
- getExportItem
This is the method that returns the item of the type specified in ExcelExportObject.
- setExportItem
This is the method that adds the item to be exported to a specific location in ExcelExportObject.
- exportimage
This is the property that sets the export method of the image set in the cell of Grid.
How to implement an example
This sample was created to run on demo.nexacro.com. To perform the sample on the user PC, WAS and nexacro-xeni must be installed and running. Also, you need to modify the url related settings in the sample script code to suit your environment. If the domains of the WAS and the user PC are different, then cross-domain problems may occur.
1
Creating Component
Select the button and the grid from the toolbar, and drag it to an appropriate size on Form to create it.
2
Creating Dataset and Entering Data
Create Dataset with the data item list to be displayed on Grid.
Select Dataset from the toolbar and click on an appropriate space on the form to create Dataset.
Enter the data item list in the created Dataset. If you double-click Dataset in the Invisible Objects area, then the Dataset Editor appears. Enter Columns and Rows as shown in the figure below.
3
Dataset Binding
Bind Dataset to the Grid component.
Binding is completed by dragging and dropping Dataset in the Invisible Objects area to the Grid component created on Form.
4
Implementing Export Function
Select Button in Form and add the onclick event handler as shown below.
this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo) { this.exportObj = new ExcelExportObject("Export00", this); this.exportObj.set_exportfilename("ExcelExportFile"); this.exportObj.set_exporttype(nexacro.ExportTypes.EXCEL2007); this.exportObj.set_exporturl("http://localhost:8080/deploy/XExportImport"); this.exportObj.addExportItem(nexacro.ExportItemTypes.GRID, this.Grid00, "Sheet1!A1"); var objExportItem = this.exportObj.getExportItem(nexacro.ExportItemTypes.GRID, 0); objExportItem.set_exportimage("image"); this.exportObj.setExportItem(nexacro.ExportItemTypes.GRID, 0, objExportItem); this.addEventHandler("onsuccess", this.Export00_onsuccess, this); this.addEventHandler("onerror", this.Export00_onerror, this); var intExportedItem = this.exportObj.exportData(); trace("Number of Exported Item: " + intExportedItem); };
5
Implementing Event Handler
this.Export00_onsuccess = function(obj:ExcelExportObject, e:nexacro.ExcelExportEventInfo) { trace("Export00_onsuccess"); } this.Export00_onerror = function(obj:ExcelExportObject, e:nexacro.ExcelExportEventInfo) { trace("Export00_onerror"); }
6
Checking with QuickView
Run it with QuickView (Ctrl + F6).
Click the Export button to check whether the data and image are exported as an Excel file on Grid of the screen.
Exporting Multiple Grid Data as Excel File
When exporting multiple Grids to an Excel file using ExcelExportObject, you can export by specifying one or multiple sheets. This is because you can specify where to export in the addExportItem method that adds the component to be exported to the ExcelExportObject.
The export location can be determined by setting strRange among the parameters of the addExportItem method. When setting strRange, use the format of "Sheet Name! Cell Area" or "Cell Area". For example, if you want to export Grid to cell C3 of the export2 sheet, then set it to "export2!C3".
Example
The following is an example of exporting 2 Grids on the screen to an Excel file using ExcelExportObject.
There are 2 buttons to perform the export. If you click the Export to 1 sheet button, all 2 Grids are exported as 1 sheet, and if you click the Export to 2 sheets button, 2 Grids are exported as 2 sheets, respectively.
sample_excelexportimport_04.xfdl
The following shows the contents of the Excel file created as a result of the execution.
If you look at the exported ExcelExportFile00.xls after pressing the Export to 1 sheet button, then you can see the result of exporting Grid00 to Cell A1 of Sheet1 and Grid01 to Cell A11 of Sheet1.
If you look at the exported ExcelExportFile01.xls after pressing the Export to 2 sheets button, then you can see that Gird00 has been exported to Cell A1 of Sheet1 and Grid01 to Cell A1 of Sheet2.
Core features used in the example
- clearExportItems
This is the method that deletes the specified item from ExcelExportObject. When deleted, it is excluded from export.
- addExportItem
This is the method that adds the item (component) to be exported to the export list of ExcelExportObject. Currently, only Grid is supported.
How to implement an example
This sample was created to run on demo.nexacro.com. To perform the sample on the user PC, WAS and nexacro-xeni must be installed and running. Also, you need to modify the url related settings in the sample script code to suit your environment. If the domains of the WAS and the user PC are different, then cross-domain problems may occur.
1
Creating Component
Create 2 Button components and 2 Grid components respectively, and place them as shown in the example. Select Button and Grid from the toolbar, and drag it to an appropriate size on Form to create it.
2
Creating Dataset and Entering Data
Create Dataset with the data item list to be displayed on Grid.
Select Dataset from the toolbar and click on an appropriate space on the form to create Dataset.
Enter the data item list in the created Dataset. If you double-click Dataset in the Invisible Objects area, then the Dataset Editor appears. Enter Columns and Rows as shown in the figure below.
3
Dataset Binding
Bind the created Dataset to each of the two grids.
Binding is completed by dragging and dropping Dataset in the Invisible Objects area to the Grid component created on Form.
4
Implementing Export to 1 sheet Button Function (Exporting 2 Grids to 1 Sheet)
After selecting the Export to 1 sheet button on Form, add the onclick event handler as shown below.
this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo) { this.exportObj = new ExcelExportObject("Export00", this); this.exportObj.set_exporturl("http://localhost:8080/deploy/XExportImport"); this.exportObj.set_exportfilename("ExcelExportFile00"); this.exportObj.set_exporttype(nexacro.ExportTypes.EXCEL2007); this.exportObj.clearExportItems(nexacro.ExportItemTypes.GRID); this.exportObj.addExportItem(nexacro.ExportItemTypes.GRID, this.Grid00, "Sheet1!A1" ); this.exportObj.addExportItem(nexacro.ExportItemTypes.GRID, this.Grid01, "Sheet1!A11" ); var nCount = this.exportObj.exportData(); };
5
Implementing Export to 2 sheets Button Function (Exporting 2 Grids to 2 Sheets)
After selecting the Export to 2 sheets button on Form, add the onclick event handler as shown below.
this.Button01_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo) { this.exportObj = new ExcelExportObject("Export01", this); this.exportObj.set_exporturl("http://localhost:8080/deploy/XExportImport"); this.exportObj.set_exportfilename("ExcelExportFile01"); this.exportObj.set_exporttype(nexacro.ExportTypes.EXCEL2007); this.exportObj.clearExportItems(nexacro.ExportItemTypes.GRID); this.exportObj.addExportItem(nexacro.ExportItemTypes.GRID, this.Grid00, "Sheet1!A1" ); this.exportObj.addExportItem(nexacro.ExportItemTypes.GRID, this.Grid01, "Sheet2!A1" ); var nCount = this.exportObj.exportData(); };
6
Checking with QuickView
Run it with QuickView (Ctrl + F6).
Click the Export to 1 sheet button and check that all 2 Grids are exported as 1 Sheet 1 in the Excel file.
Click the Export to 2 sheets button and check that the 2 Grids are exported to the Excel file as Sheet1 and Sheet 2 respectively.