Skip to main content

Tags and Text Within One Excel Cell


This article will show you various ways of combining Tags and text in Excel. Any time a Tag will be sharing a cell with text, you must create the Tag first, then insert the text into specific areas within the Formula Bar.


Simple Example

Suppose you needed to have a single cell contain the text "Invoice No." and a tag, or "Date" and a tag. Before you type the text, you must insert at least one tag. We will use an Out Tag for both, and formatted them so that our numbers and dates appeared correctly.

 (See the Out Tag Reference article for more information on formatting).


Once these tags are in place, you can use the Formula Bar in the Excel Ribbon to insert the text so that when you Output, the text and tagged data are in the correct order. Because AutoTag is interpreted as a function by Excel, the text you want to appear must be inserted into a specific location within the Select Statement.


To appear before the tagged data, your text must be inserted in between the  "  and  <  in the Formula Bar:

  • =autotag("Invoice No.  <wr:out select='select dbo.Orders.OrderID from dbo.Orders' datasource='MSSQL'/>")
  • =autotag("Date:  <wr:out select='=TODAY()'format='category:date;type:4;format:MM/dd/yy~@;' datasource='MSSQL'/>")

Note that there are two spaces after the text to create some space between the text and the data in the final document.


Now your cells will show the tags and the text. As always, you can format the cells to fit your needs.



When we Output, the example looks like this:



Advanced Examples

This section is intended to show some possibilities and limitations of text and Tags in Excel. Here are some general tips:

  • You must use the Formula Bar because the Tag Editor will only show you data about the tag you have currently selected.
  • Text must be within the AutoTag formula, and must also be outside the carets <> containing the Select Statement(s).
  • Text can be inserted so that it appears before, between, and/or after a Tag.


Avoiding Errors

Don't add Tags to a cell that already contains text.

If you have a cell that already contains text and then you click to insert a tag, it will launch the Tag Builder and even let you insert a tag. But the tag will not be recognized as a function by Excel and will not work. The tag will be treated just like normal text:



Don't insert text before the  =  in the Formula Bar

If you already have a tag inserted into a cell and you add text before the  =  in the Formula Bar, Excel will no longer recognize the tag as a formula and the whole cell will be treated as text.



Don't place text after the  ()  in the Formula Bar

If you already have a tag inserted into a cell and you place your text after the  ()  in the Formula Bar, Excel will try to use your text as if it was part of the formula and will get confused:


Inserting Text Correctly

How to place text between Tags in a single cell

You can place tags between two tags as long as you place the text between the ending and beginning carets  >< .

  • =autotag("<wr:forEach select='select EmployeeID, LastName, FirstName, Title, Region from dbo.Employees' var='var2' nickname='[Employees]' datasource='MSSQL'> CAN PLACE TEXT HERE <wr:out select='&apos;${var2.EmployeeID}' type='NUMBER' nickname='[EmployeeID]'" & " datasource='MSSQL'/>")


How to insert text after a Tag

As shown in the first example, you can insert text before a tag, but you can also insert text after a tag:

  • =autotag("*TEXT_ONE*<wr:out select='&apos;${var2.Region}' nickname='[Region]' datasource='MSSQL'/> *TEXT_TWO*")



Here is an example of the Output using the table above (plus a tiny bit of formatting). Note the placement of the text and the data from the tags.


How to use or avoid repeating text with ForEach Tags

In the Output example above, notice that the text from included between the ForEach Tags, and all the text from the Out Tags was repeated along with the data each tag retrieved. Remember that anything which is included inside a ForEach loop will be repeated. 




Now you're ready to get creative with your tag and text placement!

  • Was this article helpful?