Component: Excel

 Show all Hide all

Exports data to Microsoft Excel.

Not intended for exporting large amounts of data.

Component mode: Export

Component exports an Excel document with a single table populated from the menu item's SQL.

Creates either a tab-separated text file or an xlsx-file, which can both be opened in Microsoft Excel.

All cells are given the Excel cell format "Text" with the following important exceptions:

  • The cell format for a column without field info is undefined.

  • Cells with an integer datatype are given the cell format "Number" with zero visible decimal places.

  • Cells with a numeric or floating point datatype are given the cell format "Number" with the number of visible decimal places given by the field info.

  • Cells with the bit datatype are given the cell format "Text" and the value ”Yes” or ”No” expressed in the users language.

  • Cells with a date/time datatype and a field type of Date or Datetime are given the cell format "Date" with the type set to the display format given by the field info.

  • Cells with a date/time datatype and a field type of Time are given the cell format "Time" with the type set to the display format given by the field info.

Exported cells are given the same allignment as specified by field info. The following CSS-attributes are supported for styling:

  • color
  • background-color
  • font-weight: bold
  • font-style: italic
  • text-decoration: underline
Supported modes: Export | Template

File mode: Download

The user downloads the file.
Supported modes: Download | Save | Save and download | Batch

Repeated pages

#test

test

Component settings

Document format
The format of the generated Excel file. The default value is taken from the ExcelExportDefaultDocType application variable.
Possible value Description
xlsx The document is generated as a Microsoft Excel 2007 (*.xlsx) document. InfoSql and style information will be rendered.
text The document is generated as tab separated text. InfoSql and style information will not be rendered. This mode causes a warning when opened in Microsoft Excel 2007 and later versions.

SQL

SQL Call: Excel document data (mandatory)

SQL-statement that generates the Excel-document.
Supports custom errors: No
May modify database: No

Parameters:

@DocumentId mandatory string
This parameter is only supplied in batch mode.

Resultset: Data

Repeat mode: repeated exactly once
Row count: zero or more rows

Columns:

xxx optional string
A column with data to display in the excel document.

Resultset: Dynamic field information

Specify extra properties for the columns to export to Excel.

NOTE: In order to be compatible with grid.aspx this must be the third resultset or later, otherwise specified properties will not be applied. This means you must return an empty resultset after the data resultset in order to use this feature.
Repeat mode:
Row count:

Columns:

<xxx> optional string
Set property <xxx> for the field specified in adminfieldname. If set to null the value will not be applied.
AdminFieldName mandatory string
The name of the field to apply the information to. The presence of this column indicates that the resultset specifies field information.
ButtonJavaScript<xxx> optional string
Inserts a button next to the control that is used to execute the JavaScript supplied here. <xxx> is an arbitrary text that can be empty if only one button is required.
ButtonJavaScript<xxx>_Label optional string
The label for the JavaScript button <xxx>.
CellAlignment optional string
Specifies the alignment of the text in the field.
Possible value Description
Center Center aligned.
Left Left aligned.
Right Right aligned.
ColumnTooltip optional string
Sets the tooltip on the column title. Only supported by the Grid component.
DefaultValue optional string
The default value for the control or if prefixed by 'SQL:' the sql to run to determine the default value.
Description optional string
The description for the field.
EnabledJavaScript optional string
Javascript that controls the enabled status of the field. The control is only enabled if the expression specified here evaluates to true. The expression is evaluated every time the value of a dependent control is changed. This is only available to control types for which the enabled javascript field is visible in the user interface.
FieldGroupId optional int
The field group to use.
FieldInfoId optional int
ID of field information to base the dynamic field on. All properties not explicitly overridden by dynamic field information will be copied from this field. The referenced field must be found in the menu item's field tables.
FieldLabel optional string
If present the field label is used as the heading for fields instead of the field name.
FieldType optional string
The name of the control type to use.
Height optional int
The height of the control.
IgnoreOnSave optional bit
Do not pass the field value to the insert/update procedure.
InfoSqlLayout optional string
Where the label is shown in relation to the contents in InfoSQL.
Possible value Description
LabelAbove Full width, label above.
NoLabel Full width, no label.
Standard Label to the left.
NullChoice optional bit
Specifies whether the control allows null values.
NumberOfDecimals optional int
The number of decimals to display for numeric values.
OnChangeJavaScript optional string
Javascript run when the value of the control has changed.
OutputFormat optional string
Special formatting to be applied when the field is displayed.
Possible value Description
Hyperlink
MailToLink
PhoneLink
Placeholder optional string
Text shown when the field is empty.
Sql optional string
The SQL that determines the control's behavior. (Refer to control documentation for more information)
ThousandDelimiter optional string
The thousand grouping delimiter for numeric values.
Width optional int
The width of the control.
VisibleJavaScript optional string
JavaScript that controls the visibility of the field. The control is only visible if the expression specified here evaluates to true. The expression is evaluated every time the value of a dependent control is changed.

Resultset: File name

Repeat mode: repeated zero or one time
Row count: zero or one row

Columns:

ADMINFilename optional string
Name to use for the exported Excel document. Should not end with a file extension.

SQL Call: Validate parameters

Allows you to validate the parameters supplied by the user before any other SQL is run in the component. This call is only made if the component has visible parameters, the SQL is a stored procedure, and 'Validate parameters' is checked.
Supports custom errors: No
May modify database: No

Parameters:

@force optional bit
@validateparams mandatory bit
This parameter is set to 1 by Softadmin® when this call is made.

Custom access control and logging

SQL Call: Custom access control and logging

Use this call to restrict which entries a user is allowed to view and edit, and to log which entries a user views.

Access to a menu item is normally controlled through functions and roles alone but some entities need more fine grained control. For example, a user may have access to the View Member menu item for normal members but not for members with a protected identity.

The menu items a user visits are always logged (in ADMINLogMenuItem) but for sensitive data you may need to log exactly what entries are viewed. Do the logging in this call as the common ways of viewing data (grid and InfoSQL) are not allowed to modify the database.

If you bind a scalar function instead of a stored procedure to this call then its name must end with '_GrantAccess'.
Supports custom errors: No
May modify database: Yes

Resultset: Access permissions

Return whether the user is allowed to visit the menu item with the current parameters.
Repeat mode: repeated exactly once
Row count: exactly one row

Columns:

GrantAccess mandatory bit
1 if the user is allowed to view the menu item, 0 if the user should not be allowed to view the menu item.

If 0 then an error will be logged as the user should not have been able to reach the menu item with the given parameters in the first place.

Examples

Single table Excel export

This is the most simple example. Get one document with one table.

ALTER PROCEDURE dbo.Booking_SearchSingleDate_Excel
	-- System specific parameter
	@Date	date = NULL,
	-- Component parameters
	@Template	bit	= 0,
	@Sheet	varchar(MAX) = NULL,
	@Table	varchar(MAX) = NULL
AS
BEGIN
	/* 
	 * This example does not use batch-mode, just returning an excel file with one page.
	 */
	 ----------------------------------------------
	 -- Anrop 1. Return template to use. --
	 ----------------------------------------------
	IF @Template = 1
	BEGIN
		SELECT
			AD.Document [TemplateDocument],
			'Dagsvy_'+ CONVERT(varchar(10), @date, 20) + '.xlsx' [TemplateDocumentFileName]
		FROM
			dbo.ADMINDocument AD
		WHERE
			AD.DocumentId = 10;
		RETURN;
	END

	------------------------------------
	-- Anrop 2. Fill separate cells. --
	------------------------------------
	IF @Sheet IS NOT NULL AND @Table IS NULL
	BEGIN
		-- No separate cells to fill
		RETURN;
	END
	-----------------------------
	-- Anrop 2. Fill table. --
	-----------------------------
	IF @Table IS NOT NULL
	BEGIN
		SELECT
			*
		INTO
			#Booking
		FROM
			dbo.Booking_Search_Definition();

		INSERT INTO #Booking
		EXEC dbo.Booking_Internal_Search
				@BookingTypeId	= NULL,	
				@HasEnlister		= NULL,
				@Status			= 7,	
				@guideid		= NULL,
				@entryid			= NULL,
				@IsDeleted		= 0,
				@SingleDate		= @Date,
				@HideStaffLed	= 0

		-- Rename the columns so that they match the kolumn names in the Excel template.
		SELECT
			B.BookingTypeName [Bokningstyp],
			B.times [Tid],
			B.Organization [Organisation],
			B.GroupName [Gruppnamn],
			B.VisitorCount [Antal],
			B.guide [Guide],
			B.Comment [Kommentar]
		FROM
			#Booking B
		ORDER BY
			B.times ASC
	END
END