Pattern: Convert HTML Table to Catalytic Data Table

Options
Thomas_937381
Thomas_937381 Posts: 196
edited July 2020 in Show and Tell

If you have (HTML) tables contained in the body of an email message that need to be in .xlsx, .csv, or table format, the attached pattern will allow you to do so.

One of the fields from an email trigger is html. With this, we:

  1. Use Text: Find text next to other text to parse the portion of the HTML containing a table
  2. Remove line breaks, then commas (which will act as our delimiter)
  3. Replace the </td> tag with commas
  4. Replace the <tr> tag with a line break (\n), and remove the remaining HTML with the below formula:

result = fields['your-field'].replace(/\<tr(.*?)\>/g,'\n').replace(/<(?:.|\n)*?>/gm,'')

With a few small additional modifications to the text, we can create a clean data table, which can subsequently be filtered, summarize, or transformed as you require.

Comments

  • Thomas_937381
    Thomas_937381 Posts: 196
    edited July 2020
    Options

    I forgot to add that the table being embedded in the email for this test has just two columns, and looks like this:

    Item Value
    123 $500
    456 $400
    789 $300