Cells to Dataset Action Icon

Cells to Dataset

Declaration

<AMEXCELCELLSTODATASET RESULTDATASET="text" STARTCELLROW="number" STARTCELLCOLUMN="number" ENDCELLROW="number" ENDCELLCOLUMN="number" />

See Also

Activate Cell | Activate Worksheet | Add Worksheet | Cells to Dataset | Close Workbook | Create Workbook | Dataset to Cells | Get Active Cell | Get Active Worksheet | Get Cell | Open Workbook | Set Cell

Description

Populates a dataset with a selected range of cells in an established Excel session.

IMPORTANT: AutoMate's Excel actions use Microsoft's Excel automation engine to perform their work. Therefore, Microsoft Excel must be licensed and installed on the system in order for these actions to work.

Practical Usage

When performing Excel related tasks, you often need to run the same block of actions on each cell in a range of cells. You can use the 'Cells to Dataset' action to retrieve the contents of a range of cells in a Microsoft Excel document and combine a looping statement using the Loop Dataset action to identify each cell, one at a time, and run the operation.

NOTE: This action is only useful in conjunction with other Excel actions found in AutoMate. It is not possible to use Automate's Excel actions on a spreadsheet that was not opened by the Open Workbook action or created by the Create Workbook action.

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

Session Name

Text

Yes

ExcelSess1

SESSION="ExcelSess7"

The name of the session to associate with this Excel action. Numerous sessions can exist within a single task allowing several spreadsheets to be open simultaneously. If working with only one document, this can remain at the default session name, which is Excelsess1.

Create and Populate Dataset

Text

Yes

(Empty)

RESULTDATASET="datasetname"

The name of the AutoMate dataset that should be populated with the contents of the desired cells at runtime. More on datasets below under Notes.

Start Row

Number

No

1

STARTCELLROW="3"

The start row of the cells where the data should be retrieved. If a value is entered in this parameter, you must also enter a value in the STARTCELLCOLUMN, ENDCELLCOLUMN and ENDCELLROW parameters.

This parameter is available only if the Cell by position option is enabled. If the Cell by reference option is enabled, this parameter is ignored.

End Row

Number

No

2

ENDCELLROW="4"

The end row of the cells where the data should be retrieved. If a value is entered in this parameter, you must also enter a value in the STARTCELLCOLUMN, ENDCELLCOLUMN and STARTCELLROW parameters.

This parameter is available only if the Cell by position option is enabled. If the Cell by reference option is enabled, this parameter is ignored.

Start Column

Number

No

1

STARTCELLCOLUMN="2"

The start column of the cells where the data should be retrieved. If a value is entered in this parameter, you must also enter a value in the ENDCELLCOLUMN, STARTCELLROW and ENDCELLROW parameters.

This parameter is available only if the Cell by position option is enabled. If the Cell by reference option is enabled, this parameter is ignored.

End Column

Number

No

3

ENDCELLCOLUMN="5"

The end column of the cells where the data should be retrieved. If a value is entered in this parameter, you must also enter a value in the STARTCELLCOLUMN, STARTCELLROW and ENDCELLROW parameters.

This parameter is available only if the Cell by position option is enabled. If the Cell by reference option is enabled, this parameter is ignored.

Start Cell Reference

Text

No

A1

STARTCELLREF="C1"

The start cell reference of the cells where the data should be retrieved. This is an alternate method to specifying the row and column of the desired cell.  If specified, the STARTCELLCOLUMN, ENDCELLCOLUMN,  STARTCELLROW and ENDCELLROW parameters are ignored. If specified,  the ENDCELLREF parameter must also be specified.

End Cell Reference

Text

No

C2

ENDCELLREF="E3"

Specifies the end cell reference of the cells where the data should be retrieved. This is an alternate method to specifying the row and column of the desired cell. If specified, the STARTCELLCOLUMN, ENDCELLCOLUMN,  STARTCELLROW and ENDCELLROW parameters are ignored. If specified, the STARTCELLREF parameter must also be specified.

Use specific worksheet

Text

No

Sheet1

WORKSHEET="Sheet3"

If enabled, indicates that the data will be retrieved from a specific worksheet instead of the currently active worksheet. Enter the name of the appropriate worksheet in the provided textbox. If left blank or omitted, the current active worksheet will be used.

 

Description Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab properties allows you to instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Notes

Datasets

A dataset is a multiple column, multiple row container object. This action creates and populates a dataset, the fields contained within that dataset are determined by the query that was executed. For example if the following query is executed:

 

SELECT firstname, lastname, company from customer where city='Los Angeles'

 

 

Then the following dataset would be generated:

datasetname
|--firstname
|--lastname
|--company
 

A record (row) is created for each record (row) that is retrieved from the server. To access this data use the Loop Dataset Action <AMLOOPDATASET> to loop through the records, inside the loop you can extract the data from the field of your choice (from the current record) by using an embedded expression such as the one that follows:

 

%mydatasetname.firstname%

 

 

Or you could combine two fields together like this:

 

%mydatasetname.firstname + " " + mydatasetname.lastname%

 

 

Embedded Expressions such as these can be used in any parameter in any action. So, to display the data in a message box the AML code would look like this:

 

<AMMESSAGEBOX MESSAGETEXT="%mydatasetname.firstname%" WINDOWTITLE="The firstname of the current record is">

 

 

At runtime the text %mydatasetname.firstname% is replaced by the contents of the subject of the current record.

Common Name Description

The table below describes the common set of columns that a dataset creates (assuming the dataset name assigned is theDataset).

Name

Data Type

Return Value

theDataset.CurrentRow

Number

The current row that will be accessed in the dataset by an expression that does not contain a specific row index.

theDataset.TotalRows

Number

The total number of rows in the dataset.

theDataset.TotalColumns

Number

The total number of columns (not including the static columns) in the dataset.

theDataset.ExecutionDate

Date

The date and time the dataset was created and populated.

theDataset.RowsAffected

Number

The number of rows affected by an update.

theDataset.SQLQuery

Text

The SQL Query that was used to generate this dataset (If a SQL Query was not used, this value is empty).

theDataset.Datasource

Text

The datasource used for the SQL Query, if applicable.

theDataset.ColumnNames

Text

A comma-delimited list of the column names in the dataset.

 

More on datasets

Custom Description

This action includes the Description tab for entering a custom step description.

More on setting custom step description

Standard Error Handling Options

This action also includes the standard Error Causes and On Error failure handling options/tabs.

More on Error Handling Options

Variables and Expressions

All text fields allow the use of expressions, which can be entered by surrounding the expression in percentage signs (example: %MYVARIABLE%, %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by pressing F2.

More on variables
More on expressions

More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 

Description: This sample task opens an existing spreadsheet, retrieves the data contained in the first 3 rows of column A and populates a dataset with the results. The data is then looped through. A message box is contained inside the loop to display the value of the current row. In order for this task to work, make sure to edit the properties of the 'Open Workbook' action (step 1) to point to a valid Excel file that contains data in the first 3 rows and columns.

 

<AMEXCELOPENWORKBOOK WORKBOOK="C:\Temp\myexceldocument.xlsx" />

<AMEXCELCELLSTODATASET RESULTDATASET="mydataset" STARTCELLROW="1" STARTCELLCOLUMN="1" ENDCELLROW="3" ENDCELLCOLUMN="1" />

<AMLOOP TYPE="DATASET" DATASET="mydataset">

     <AMSHOWDIALOG>The value of row %mydataset.CurrentRow%, column A is %mydataset.A%.

</AMSHOWDIALOG>

</AMLOOP>

<AMEXCELCLOSEWORKBOOK SAVE="NO" />

 

↑ Top of Page