Tuesday, March 11, 2025

Reading from multiple regions in an Excel worksheet with Liquid Data Mapper

This tutorial demonstrates how to extract and transform data from multiple regions within an Excel worksheet and use them within a data mapper transform, merging the data into a single output file.

Let's assume we have a worksheet that looks something like this (Data.xlsx):

The worksheet contains 3 tables, one for each salesperson.

We want to combine them all into a single XML file complying with the XSD Schema (Sales.xsd):

Method 1

The easiest way to work with regions within an Excel worksheet is to create a table for each region. 
Note: If changing the Excel worksheet is not an option then have a look at Method 2.


This can be done by selecting the cells in the region, the using the Insert->Table option.

You can then name this table by using the Formulas->Name Manager option.

The file Data_Version2.xlsx contains the original Data.xlsx file with the addition of tables.

Note: Named cell ranges can also be used instead of tables.

Now when you create a new Data Mapper file and import data from your Excel file you will see the tables you have created in the import list.


If we also add an XML target based on our XSD Schema (Sales.xsd) then after adding a few connections we end up with a transform that looks like this:

Executing this transform will give us the 'Fred' sales in XML format:
<Sales>
<Sale>
<Name>Fred</Name>
<Date>2005-01-01</Date>
<Desc>1000 Pens</Desc>
<Total>19.99</Total>
</Sale>
<Sale>
<Name>Fred</Name>
<Date>2005-01-02</Date>
<Desc>5 Laptops</Desc>
<Total>749</Total>
</Sale>
<Sale>
<Name>Fred</Name>
<Date>2005-01-03</Date>
<Desc>1 Stress ball</Desc>
<Total>5.49</Total>
</Sale>
</Sales>
In order to add the other 2 salesperson's data we add 2 more Excel reader components, selecting the appropriate table for each.


We want to combine these additional data sources into our single output XML file. We can do this by duplicating the output node 'Sale' on the XML writer and connecting each Excel source to its own copy.

Now when we run the transform we get the results from all 3 salespeople.
<Sales>
<Sale>
<Name>Fred</Name>
<Date>2005-01-01</Date>
<Desc>1000 Pens</Desc>
<Total>19.99</Total>
</Sale>
<Sale>
<Name>Fred</Name>
<Date>2005-01-02</Date>
<Desc>5 Laptops</Desc>
<Total>749</Total>
</Sale>
<Sale>
<Name>Fred</Name>
<Date>2005-01-03</Date>
<Desc>1 Stress ball</Desc>
<Total>5.49</Total>
</Sale>
<Sale>
<Name>Sue</Name>
<Date>2005-01-02</Date>
<Desc>200 Memory sticks</Desc>
<Total>1400</Total>
</Sale>
<Sale>
<Name>Sue</Name>
<Date>2005-01-05</Date>
<Desc>1 Label Printer</Desc>
<Total>35</Total>
</Sale>
<Sale>
<Name>James</Name>
<Date>2005-01-03</Date>
<Desc>25 Keyboards</Desc>
<Total>150</Total>
</Sale>
<Sale>
<Name>James</Name>
<Date>2005-01-05</Date>
<Desc>2000 Notepads</Desc>
<Total>450</Total>
</Sale>
<Sale>
<Name>James</Name>
<Date>2005-01-06</Date>
<Desc>3 Printer Cartridges</Desc>
<Total>169</Total>
</Sale>
<Sale>
<Name>James</Name>
<Date>2005-01-09</Date>
<Desc>1 Inspiring cat poster</Desc>
<Total>0.99</Total>
</Sale>
</Sales>

What if data in the Excel file changes?

If rows are added or removed from the tables within the Excel worksheet then when the transform is re-run it will incorporate the changes made in the Excel worksheet.

The columns are assigned based on there position, so the 1st column is assumed to be 'Date', the 2nd 'Description' the 3rd 'Total'. Additional columns can be added but changes to the ones defined in the data mapper will cause issues.

Method 2

If it is not possible to modify the Excel worksheet, then the Excel data sources within the Data Mapper transform can be defined using Custom Ranges.

Taking this approach you have to manually select the region within the worksheet i.e. Sheet1!A2:C5.


The 'Dynamically expand range' option

At this point it is important to consider what happens when data is added/removed from the worksheet. 
If this option is NOT checked then the range of cells selected is fixed, adding or removing rows will still result in the data source returning the same number of rows in the DataMapper. This is useful when you are loading fixed lookup values, but not for dynamic data.

If this option IS checked then the range of cells selected dynamically changes depending on the data in the workbook. Starting on the first data row and moving down until an empty row is encountered.

Example


If the custom range was set to 'Sheet1!A2:C5' and the Excel sheet now looks like this

If 'Dynamically expand range' = false, the data for '1000 Pens', '5 Laptops' & '1 Stress ball' would be returned.

If 'Dynamically expand range' = true, the data for '1000 Pens', '5 Laptops', 1 Stress ball' & ' 25 Keyboards' would be returned. Note: '1 Label Printer' is NOT returned as the first empty row ends the table (Row 7).

Summary

If you are gathering data from multiple regions on an Excel worksheet then your best option is to set up either Excel Tables or Named Regions. These can then be imported into the DataMapper, and changes to the Excel data is reflected in the DataMapper.

If changing the Excel worksheet is not possible then you can import custom regions, which can be set to dynamically load data from the Excel worksheet so the DataMapper will import newly added Excel rows .

Download a Free Trial and Free Community Version:
https://www.liquid-technologies.com/trial-download

Example Files


Friday, February 28, 2025

New Release - Liquid Studio v21

What's New from Liquid Technologies?

Liquid Technologies have announced the availability of Liquid Studio v21 and Liquid XML Data Binder v21, providing many new features and enhancements plus general performance and stability improvements.

The new release extends and improves on the existing functionality by introducing other new tools and technologies that our users have requested in order to continue to make Liquid Studio the best value XML development environment available.

Liquid Studio Framework

  • NEW Blue Theme
  • NEW looking Dark Theme
  • NEW Rendering for Windows 11 styling for graphical elements such as scrollbars and window docking
  • Improved support for High DPI monitors
  • Improved all user settings are stored when upgrading product versions
  • Added all Wizards to the Tools Convert Menu
  • Added .jschema to file filters
  • Added information bar when Design and Source Code views need refreshing
  • Security Vulnerability Fix: Removed use of deprecated DotNetZip library

Liquid Data Mapper

  • NEW BSON to JSON Component
  • NEW Fast Infoset to XML Component
  • NEW JSON to BSON Component
  • NEW XML to Fast Infoset Component
  • NEW Create Time Span Component
  • NEW FTP Get Component
  • NEW FTP Put Component
  • NEW Read Binary File Component
  • NEW Write Binary File Component
  • NEW XSLT support for Set Timezone Component
  • NEW XSLT support for To Local XSLT Component
  • NEW XSLT support for To Utc XSLT Component
  • NEW XSLT 3.0 Code Generation Option
  • Improved Text Reader Wizard when using Fixed Length Fields

Liquid Data Mapper C# and VB.Net Runtime Nuget

  • NEW .Net Runtime support for .Net 9.0 and .Net 8.0
  • Security Vulnerability Fix: Upgraded Newtonsoft.Json Nuget dependency to prevent Improper Handling of Exceptional Conditions resulting in Denial Of Service (DoS).
  • Security Vulnerability Fix: Removed dependency of deprecated ClosedXML.Signed Nuget.
  • Improved Performance in .Net Runtime
  • Removed unnecessary dependency on RedGate.SmartAssembly.Attributes Nuget.

XPath, XSLT and XQuery

  • NEW Integration with Saxon-HE v12.5
  • NEW Added XSLT 3.0 option to XSLT Wizard
  • Upgraded XSD 1.1 validation with Xerces v2.12.2
  • Improved XPath Query Builder to store XPath for individual files
  • Fixed initialisation timeout errors in XSLT and XQuery Debuggers

Web Service Testing

  • NEW OpenAPI (REST) Web Service Call Testing for OpenAPI 3.1 Web Services
  • NEW Bearer Token Credentials option
  • NEW JSON Web Tokens (JWT) Credentials option
  • NEW Custom Headers at Web Service Connection Level

JSON Editor

  • NEW BSON to JSON conversion
  • NEW JSON to BSON conversion
  • NEW JSON to YAML conversion
  • Improved OpenAPI JSON to YAML conversion with options for OpenAPI 2, 3, and 3.1
  • Fixed issue where Infer JSON Schema from JSON Wizard always used default file

XML Schema (XSD) Editor

  • Improved editor to allow Pattern Facet to store multiple values

YAML Editor

  • NEW YAML to JSON conversion
  • Improved OpenAPI YAML to JSON conversion with options for OpenAPI 2, 3, and 3.1

NEW Graphical Markdown Editor with Split View and Design and Source Code Views

  • NEW Markdown to HTML conversion

HTML Editor

  • NEW HTML to Markdown conversion

RelaxNG Editor

  • Improved Validation

XML Data Binder

  • NEW .Net Runtime support for .Net 9.0 and .Net 8.0
  • Improved all user settings are stored when upgrading product versions
  • Improved Command Line Parameter checking

XML Data Binder C++ Runtime

  • NEW Linux C++ Runtime support for gcc 14.2, 13.3, 12.4, 11.5, 10.5
  • NEW Linux C++ Runtime support for PCRE2
  • NEW Windows C++ Runtime support for PCRE2

XML Data Binder C# and VB.Net Runtime Nuget

  • NEW .Net Runtime support for .Net 9.0 and .Net 8.0
  • Improved Performance in .Net Runtime

Liquid XML Objects

  • NEW .Net Runtime support for .Net 9.0 and .Net 8.0

Liquid XML Objects C# and VB.Net Runtime Nuget

  • NEW .Net Runtime support for .Net 9.0 and .Net 8.0
  • Improved Performance in .Net Runtime
  • Removed unnecessary dependency on RedGate.SmartAssembly.Attributes Nuget.

General Improvements

  • Along with the new features outlined above, existing features have also been enhanced and improved with functionality requested by our users.


Liquid Studio 21 is a Free upgrade for all users with an active support plan.

Download a Free Trial and Free Community Version:
https://www.liquid-technologies.com/trial-download