Excel Connector

Version 23.3.8698


Excel Connector


The Excel connector converts data between Excel sheets (.xlsx) and XML files.

Overview

Excel connectors can be configured in two modes: Table and Template. These modes are described below.

Table Mode

The default mode for Excel connectors is Table. This mode only supports converting files from XLSX to XML. To convert from XML to XSLX, use Template mode.

In Table mode, the connector treats input XLSX files exactly like CSV files. The resulting output XML file has the following structure, where each row (record) in the original file becomes a child of the root element Items:

<Items><Record>
  <field_0></field_0>
  <field_1></field_1>
  <field_2></field_2></Record>
</Items>

Template Mode

In Template mode, the connector uses a template file to perform conversions. This template file matches the output file format:

  • When converting from XML to Excel, the template file is an Excel file.
  • When converting from Excel to XML, the template file is an XML file.

These template files use ArcScript to dynamically populate the output files with data from the input files. For more information, see the Templates section.

Connector Configuration

This section contains all of the configurable connector properties.

Settings Tab

Configuration

Settings related to the core configuration of the connector.

  • Connector Id The static, unique identifier for the connector.
  • Connector Type Displays the connector name and a description of what it does.
  • Connector Description An optional field to provide a free-form description of the connector and its role in the flow.
  • Translation Mode Specify which method (Table or Template) to use to translate the input file to the output format. See the Overview for more information.
  • Column headers (Table mode) Check this to have the translation use the values in the first row of the XLSX file as the element names of the child elements. If unchecked, the value elements are given generic names such as field_0, field_1, etc.
  • Template File (Template mode) The file that functions as the output template. Data is dynamically added to the file based on the scripting in the template. See the Templates section for details.

Advanced Settings

Settings not included in the previous categories.

  • Start Row (Table mode) The first row in the sheet to use for the output table.
  • Start Column (Table mode) The first column in the sheet to use for the output table.
  • End Column (Table mode) The last column in the sheet to use for the output table. If not set, the column preceding the first empty cell on the first row is detected as the end of the sheet.
  • DateTime Format (Table mode) The format to use for DateTime values in the Excel document.
  • Number Format (Table mode) The format to use for numbers in the Excel document. Set this if you want all numbers in the document to be handled in the same way.
  • Local File Scheme A scheme for assigning filenames to messages that are output by the connector. You can use the following macros to reference contextual information:
    %ConnectorId%, %Filename%, %FilenameNoExt%, %Ext%, %ShortDate%, %LongDate%, %RegexFilename%, %DateFormat%, %Header%.
    For example: %FilenameNoExt%_%ShortDate%%Ext%

Message

Message settings determine how the connector searches for messages and manages them after processing. You can save messages to your Sent folder or you can group them based on a Sent folder scheme, as described below.

  • Save to Sent Folder A toggle that instructs the connector to keep a copy of sent messages in the Sent folder.
  • Sent Folder Scheme Instructs the connector to group files in the Sent folder according to the selected interval. For example, the Weekly option instructs the connector to create a new subfolder each week and store all sent files for the week in that folder. The blank setting instructs the connector to save all files directly in the Sent folder. For connectors that process many transactions, using subfolders can help keep files organized and improve performance.

Logging

  • Log Level The verbosity of logs generated by the connector. When you request support, set this to Debug.
  • Log Subfolder Scheme Instructs the connector to group files in the Logs folder according to the selected interval. For example, the Weekly option instructs the connector to create a new subfolder each week and store all logs for the week in that folder. The blank setting tells the connector to save all logs directly in the Logs folder. For connectors that process many transactions, using subfolders helps keep logs organized and improves performance.
  • Log Messages Check this to have the log entry for a processed file include a copy of the file itself. If you disable this, you might not be able to download a copy of the file from the Input or Output tabs.

Miscellaneous

Miscellaneous settings are for specific use cases.

  • Other Settings Enables you to configure hidden connector settings in a semicolon-separated list (for example, setting1=value1;setting2=value2). Normal connector use cases and functionality should not require the use of these settings.

Automation Tab

Settings related to the automatic processing of files by the connector.

Automation Settings

  • Send Whether messages arriving at the connector are automatically processed.

Performance

Settings related to the allocation of resources to the connector.

  • Max Workers The maximum number of worker threads consumed from the threadpool to process files on this connector. If set, this overrides the default setting on the Settings > Automation page.
  • Max Files The maximum number of files sent by each thread assigned to the connector. If set, this overrides the default setting on the Settings > Automation page.

Templates

XML to Excel

The following snippet from an XML file contains a list of elements under the /Items/Orders path.

<Items>
    <Orders>
        <OrderNo>PO0012345</OrderNo>
        <Customer>Teddy</Customer>
        <Date>04/19/2023</Date>
        <SubTotal>23.98</SubTotal>
        <Items>
            <Name>Teddy Bear</Name>
            <Cost>14.99</Cost>
            <Desc>Brown</Desc>
        </Items>
        <Items>
            <Name>Truck</Name>
            <Cost>8.99</Cost>
            <Desc>Red</Desc>
        </Items>
    </Orders>
</Items>

To convert this XML file to XSLX, you must create an Excel template. The image below shows an example Excel template that uses xmlDOMSearch and xpath to loop through the elements of the XML file:

Simple Template

Every Excel template must contain the following elements, which are shown in the example above:

  • Static column headers. In the example above, this is Order Detail.
  • Scripting in Excel notes. This scripting should use the xmlDOMSearch operation to loop through the input XML at a specified XPath. In the example above, this is contained in the arc:call operation.
  • Scripting in Excel cells. This scripting should use the xpath formatters to read values from the XML at a given xpath. This xpath is relative to the xpath specified in the xmlDOMSearch operation.

The details of the xmlDOMSearch operation and xpath formatters in this example are described below.

xmlDOMSearch

The xmlDOMSearch requires two parameters:

URI parameter

The URI is the resource path to the XML file to parse. The [filepath] attribute resolves to the input XML file to the connector, and the URI should almost always be set to this value. In the above example, the filepath is URL-encoded with the urlencode formatter to ensure that special characters in the filepath do not prevent the connector from reading the file: [filepath | urlencode]

xpath parameter

The xpath is the XML path to loop over in the document. The operation loops for each occurrence of the specified xpath. For example, with the xpath /Items/Orders, each Orders element that is a child of the root Items element causes a new set of output in the resulting Excel file.

xpath formatters

The Excel notes with the xmlDOMSearch operation surround a block of cells that reference the input XML via the xpath formatter. The xpath formatter reads values from the input XML at the specified xpath.

Note: this xpath is relative to the path provided as a parameter to the xmlDOMSearch operation.

In the above example, the first cell is populated with: [xpath("OrderNo")]. Since this xpath is relative, the cell is populated with the value from the following path in the input XML: /Items/Orders/OrderNo.

If the xmlDOMSearch operation loops more than once—that is, if more than one instance of the operation’s xpath parameter is found—then the block of cells between the Excel notes is repeated. The new cells are added vertically, so in the above example the second OrderNo cell would be directly below the first Notes cell.

Excel to XML

To convert from XSLX to an XML file, you must create a custom XML template using ArcScript commands. Since XML does not support the same scripting functionality as Excel files, the structure and formatting for converting from XSLX to XML is different than from XML to Excel.

Note: Due to the wide range of potential input and output structures, there is no universal solution for every conversion need. The example template shown below is just one of many potential solutions. You need to create a template based on your own needs.

This example template uses a combination of standard XML syntax and Arc Script to read, process, and convert data from an input Excel file.

The arc:set lines below specify the location of the file and the Excel version used to create the file.

<!-- Read Excel -->
<arc:set attr="xml.file" value="[FilePath]" />
<arc:set attr="xml.version" value="2007" />

The sections below specify the conversion parameters and map the headers into standard XML formatting.

The parameter [_value | toalphanum | replace(' ','')] indicates that the arc:set command should parse header names from the Excel file, convert them to alphanumeric format, eliminate blank spaces, and assign them as headers in the XML file.

<!-- Always use first sheet-->
<arc:call op="excelListSheets" in ="xml" out="sheet">
  <arc:set attr="xml.sheet" value="[sheet.sheet]" />
  <arc:break />
</arc:call>

<!-- read the headers into an array-->
<arc:set attr="xml.map:headers" value="A1:*1" />
<arc:call op="excelGet" in="xml" out="header">
  <arc:enum attr="header.headers#">
    <arc:set attr="data.headernames#" value="[_value | toalphanum | replace(' ','')]" />
  </arc:enum>
</arc:call>

<arc:set attr="_log.info" value="[data.headernames#1]" />

<arc:enum range="A..Z">
  <arc:set attr="tmp.cells#" value="[_value]" />
</arc:enum>

The sections below process the remaining data and build the data columns according to the specified structure.

<!-- read the remaining cells -->
<arc:enum attr="data.headernames#">
  <arc:set attr="xml.map:[_value]" value="[tmp.cells#[_index]]2:[tmp.cells#[_index]]*" />
</arc:enum>

<!-- build the columns -->
<arc:call op="excelGet" in="xml" out="cols">
  <arc:map from="cols" to="data" map="*=*" />
</arc:call>

<Items>
  <arc:enum attr="data.[data.headernames#1]#"><arc:set attr="tmp.colIndex" value="[_index]" />
    <Record>
      <arc:enum attr="data.headernames#">
        <[_value]>[data.[_value]#[tmp.colIndex] | def]</[_value]>
      </arc:enum>
    </Record>
  </arc:enum>
</Items>

Excel Operations

In addition to the Operations provided with Arc, connectors might provide operations that extend functionality into ArcScript. Operations specific to the functionality of the Excel connector are listed below.

excelClose

Close an Excel connection.

Optional Parameters

  • handle: The handle for the Excel file.

Output Attributes

  • success: True if the connection is closed successfully.

excelCreate

Create a new Excel worksheet.

Required Parameters

  • sheet: The name of the Excel worksheet to create inside the workbook. The default is sheet1.

Optional Parameters

  • file: The path to the Excel workbook.
  • version: The version of Excel you are using. The default is AUTO. You only need to choose another version if you are using a legacy Excel version.
  • overwrite: Indicates whether to overwrite the file if it already exists. The allowed values are true and false. The default is false.
  • columnnames: Comma-separated list of the column names of the new spreadsheet. Column names cannot contain white space.

Output Attributes

  • file: The name of the Excel workbook updated.
  • sheet: The name of the Excel worksheet created inside the workbook. This can be different from the sheet specified if the name conflicts with an existing one.

excelDelete

Delete the row by RowId in an Excel worksheet.

Required Parameters

  • sheet: The name of the Excel worksheet.
  • RowId: The start row index to delete from the document. Starts from 1.
  • count: The count of rows to delete.

Optional Parameters

  • version: The version of Excel you are using. The default is AUTO. You only need to choose another version if you are using a legacy Excel version.
  • file: The path to the Excel workbook.
  • handle: The handle for the Excel file.
  • headerlocation: Location of the column headers. The default is NONE.
  • recalculate: If true, the cell formulas that depend on the changed cells are recalculated. If not, they are calculated on the first opening in Excel. The default is true.
  • Ignorecalcerror: If true, any errors that occur due to formula calculation are ignored. If this happens the formula result might be unreliable but other data is accurate. The default is false.
  • logfile: The log file used to log any errors that occurred during the calculation.
  • CloseFile: Indicates whether to close the file now or wait until the connection is closed.

Output Attributes

  • file: The name of the Excel workbook updated.
  • sheet: The name of the Excel worksheet updated.

excelGet

Queries the specified Excel worksheet.

Required Parameters

  • sheet: The name of the Excel worksheet.

Optional Parameters

  • version: The version of Excel you are using. The default is AUTO. You only need to choose another version if you are using a legacy Excel version.
  • file: The path to the Excel workbook.
  • handle: The handle for the Excel file.
  • map:*: This set of inputs contains a mapping of the attribute name and the name of the cell whose value is to be retrieved from the spreadsheet. For example, the attribute name map:MyValue which has a value of C1 pushes an attribute named MyValue with the value found in the cell at C1 in the sheet. You can specify a range of cell names to retrieve a range of cell values.

Output Attributes

  • *: Depends on the content of the sheet and the query specified. If column headers are present they are used to name the output attributes.

excelGetHeader

Describes the specified Excel worksheet.

Required Parameters

  • sheet: The name of the Excel worksheet.

Optional Parameters

  • version: The version of Excel you are using. The default is AUTO. You only need to choose another version if you are using a legacy Excel version.
  • file: The path to the Excel workbook.
  • handle: The handle for the Excel file.
  • headerlocation: Location of the column headers. The default is NONE.
  • headernames: Comma-delimited list of column or row headers that you want to use (for example, firstName, lastName).
  • recalculate: If true, recalculate the formulas and save the results before returning values. The default is true.
  • Ignorecalcerror: If true, any errors that occur due to formula calculation are ignored. If this happens the formula result might be unreliable but other data is accurate. The default is false.
  • logfile: The log file used to log any errors that occurred during the calculation.
  • typedetectionscheme: The scheme to detect the data type.
  • rowScandepth: The row scan depth.

Output Attributes

  • *: Depends on the content of the sheet and the range specified.
  • meta:row: The index of the row in the Excel document.

excelInsert

Append a record to an Excel sheet.

Required Parameters

  • sheet: The name of the Excel worksheet.
  • cell#: The cells you want to update.
  • value#: The values you want to set to the range.

Optional Parameters

  • version: The version of Excel you are using. The default is AUTO. You only need to choose another version if you are using a legacy Excel version.
  • file: The path to the Excel workbook.
  • handle: The handle for the Excel file.
  • headerlocation: Location of the column headers. The default is NONE.
  • RowId: The index of the row appended to the document.
  • dataType#: The data types you want to set to the range.
  • allowformula: If true, the cell value that starts with an equals sign (=) is treated as a formula. The default is true.
  • recalculate: If true, the cell formulas that depend on the changed cells are recalculated. If not, they are calculated on the first opening in Excel. The default is true.
  • Ignorecalcerror: If true, any errors that occur due to formula calculation are ignored. If this happens the formula result might be unreliable but other data is accurate. The default is false.
  • logfile: The log file used to log any errors that occurred during the calculation.
  • CloseFile: Indicates whether to close the file now or wait until the connection is closed.

Output Attributes

  • sheet: The name of the Excel worksheet updated.
  • RowId: The index of the row appended to the document.

excelListSheets

Lists the worksheets in a specified Excel workbook.

Optional Parameters

  • version: The version of Excel you are using. The default is AUTO. You only need to choose another version if you are using a legacy Excel version.
  • file: The path to the Excel workbook.
  • handle: The handle for the Excel file.

Output Attributes

  • isHidden: Returns true if the sheet is hidden from view in Excel.
  • sheet: The name of the Excel worksheet. Note that the name ends with $. This is not required when specifying worksheet names to other operations.

excelOpen

Open an existing Excel workbook.

Required Parameters

  • file: The path to the Excel workbook.

Optional Parameters

  • version: The version of Excel you are using. The default is AUTO. You only need to choose another version if you are using a legacy Excel version.

Output Attributes

  • handle: The handle which is used to execute other operations.

excelUpdate

Update cells in an Excel worksheet.

Required Parameters

  • sheet: The name of the Excel worksheet.
  • RowId: The index of the row updated to the document.
  • cell#: The cells you want to update.
  • value#: The values you want to set to the range.

Optional Parameters

  • version: The version of Excel you are using. The default is AUTO. You only need to choose another version if you are using a legacy Excel version.
  • file: The path to the Excel workbook.
  • handle: The handle for the Excel file.
  • headerlocation: Location of the column headers. The default is NONE.
  • allowformula: If true, the cell value that starts with the equals sign (=) is treated as a formula. The default is true.
  • recalculate: If true, the cell formulas that depend on the changed cells is recalculated. If not, they are calculated on the first opening in Excel. The default is true.
  • Ignorecalcerror: If true, any errors that occur due to formula calculation are ignored. If this happens the formula result might be unreliable but other data is accurate. The default is false.
  • logfile: The log file used to log any errors that occurred during the calculation.
  • CloseFile: Indicates whether to close the file now or wait until the connection is closed.

Output Attributes

  • file: The name of the Excel workbook updated.
  • sheet: The name of the Excel worksheet updated.
  • range: The cell range updated.