Unofficial Content
  • This documentation is valid for:

Spanish version

Name

ExportToExcel.

Intention

Generating a procedure that will export the information from a Table to an Excel spreadsheet.  Besides, being able to specify a template to be applied to the spreadsheet and setup the row and column of the Excel spreadsheet where data will start being written.

Implementation

Assuming that the pattern is applied to a transaction like the following one: 

Customers 
	CustomerId* 
	CustomerName 
	CustomerBirthDate

A procedure like the following one will be generated:

&Filename = 'CustomerExcelExport.xls' 
&ExcelDocument.UseAutomation = 0 
&ExcelDocument.Open(&Filename) 
Do 'CheckStatus' 
&ExcelDocument.Clear()

&CellRow = 1 
&FirstColumn = 1

// Write titles 
&ExcelDocument.Cells(&CellRow, &FirstColumn + 0).Bold = 1 
&ExcelDocument.Cells(&CellRow, &FirstColumn + 0).Text = 'Customer Id' 
&ExcelDocument.Cells(&CellRow, &FirstColumn + 1).Bold = 1 
&ExcelDocument.Cells(&CellRow, &FirstColumn + 1).Text = 'Customer Name' 
&ExcelDocument.Cells(&CellRow, &FirstColumn + 2).Bold = 1 
&ExcelDocument.Cells(&CellRow, &FirstColumn + 2).Text = 'Customer Birth Date'

// Write cell values
for each     
   &CellRow += 1  
   &ExcelDocument.Cells(&CellRow, &FirstColumn + 0).Number = CustomerId  
   &ExcelDocument.Cells(&CellRow, &FirstColumn + 1).Text = CustomerName  
   &ExcelDocument.Cells(&CellRow, &FirstColumn + 2).Date = CustomerBirthDate 
Endfor

&ExcelDocument.Save() 
Do 'CheckStatus' 
&ExcelDocument.Close()

Sub 'CheckStatus'    
If (&ExcelDocument.ErrCode <> 0)        
   &Filename = ""        
   &ErrorMessage = &ExcelDocument.ErrDescription        
   &ExcelDocument.Close()        
   Return    
Endif
Endsub

Implementation of ExportToExcel Pattern

ExportToExcel Instance File ExportToExcel pattern instance file contains the following nodes:  

ExportToExcelInstanceFile

Folder - Folder where the procedure exporting to Excel will be generated. The procedure is generated by default with the following name:  Export<TRNNAme> ExcelFileName ? Name of the Excel spreadsheet to be generated.  

ExportToExcel.Config The following can be setup in this file:  

  • Template to be assigned to the Excel spreadsheet.    
  • Number of the Excel spreadsheet Row where the information will start being written.   
  •  Number of the spreadsheet Column where the information will start being written.  

Generated GeneXus Objects 

This pattern generates a procedure called Export<TRNName> that will perform the export of all data existing in an Excel table. 

Installation

Copy ExportToExcel.zip files under C:\Program Files\ARTech\Patterns11\Patterns. Then, on executing Patterns, it will appear in the list of available patterns.  

 

Last update: April 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant