5 min read
Multiple values in one Excel cell: one value per line
By Quentin Delepierre, Salesforce Commerce Cloud consultant
A list of colours, three image links, some categories: in an XML file these are tags that repeat. In a spreadsheet, the most readable way is to put them in a single cell, one value per line. Here is the shortcut for a line break inside a cell in your software, then how ExcelifyXML uses it so that each line becomes a tag again.
Got your own XML? Drop it in and see it as a table, free and with no account. For an Excel file you can edit and then rebuild into an XML that keeps its structure, a free account is all you need.
Simple Excel table, free with no account, for files up to 1 MB. File that rebuilds into XML: free account, 3 free credits, no credit card.
Line break in a cell: the shortcut for your spreadsheet
In a spreadsheet, Enter confirms the cell and moves down one row. To stay in the cell and write a second value under the first, you need a shortcut, and it differs from one program to another. Enter the cell first: double-click it, or press F2 on Windows, Ctrl+U on Mac. Then put the cursor where the new line should start.
- Excel on Windows: Alt+Enter.
- Excel for Mac: Ctrl+Option+Enter; in recent versions, Cmd+Option+Enter works too.
- LibreOffice Calc: Ctrl+Enter.
- Numbers: Option+Enter.
- Google Sheets: Ctrl+Enter on Windows and ChromeOS, Cmd+Enter on Mac.
Multiple values in one cell: the case of an XML file
In an XML file, a list is a tag that repeats: several colours, several image links, several <value> tags under one custom attribute of a Salesforce Commerce Cloud catalog. A spreadsheet cell holds one value: without care, you would need one column per value, as many as the longest list in the file, and most of them would stay empty.
ExcelifyXML therefore puts the list in a single cell, one value per line. Example with two invented attributes, colorGroup (several values) and size (a single one):
<catalog>
<product product-id="P001">
<custom-attributes>
<custom-attribute attribute-id="colorGroup">
<value>red</value>
<value>A1B2</value>
<value>blue</value>
</custom-attribute>
<custom-attribute attribute-id="size">
<value>M</value>
</custom-attribute>
</custom-attributes>
</product>
<product product-id="P002">
<custom-attributes>
<custom-attribute attribute-id="colorGroup">
<value>green</value>
</custom-attribute>
<custom-attribute attribute-id="size">
<value>L</value>
</custom-attribute>
</custom-attributes>
</product>
</catalog>@product-id , custom-attributes.custom-attribute[colorGroup].value , custom-attributes.custom-attribute[size].value
P001 , "red
A1B2
blue" , M
P002 , green , LThe “Group repeated values” option
The box “Group repeated values in one cell (one value per line)” is checked by default. On the Upload page it is in “Advanced options”, under the free preview; on the Excel workbook page it sits right under the preview and is checked by default too.
- Each line of the cell becomes a tag, in the order you write them.
- Adding a line in the cell adds a tag; deleting a line removes the tag.
- An empty line writes nothing.
- Uncheck the box to get one numbered column per value instead: custom-attributes.custom-attribute[colorGroup].value[0], then value[1], value[2]…
In the spreadsheet, step by step
- Enter the list cell: double-click, F2 on Windows, Ctrl+U on Mac.
- Put the cursor at the end of the last value.
- Press your spreadsheet's line-break shortcut (see above), then type the new value.
- To remove a value, delete its whole line, line break included.
- Confirm with Enter and save, then drop the file on the Rebuild page (the Excel file alone, or the data.csv with its skeleton.json): each line becomes a tag again.
Which lists are not grouped
The option groups a list only when nothing can be lost in the cell. Otherwise the list keeps one numbered column per value, with no error message, exactly as if the box were unchecked:
- tags that carry attributes or sub-tags (an <image> with an attribute, a <variant> with its fields): they keep one column per attribute and per sub-tag;
- values that are empty, on several lines, or with a space at the start or the end;
- values a spreadsheet could convert: leading zeros (007), long codes such as an EAN, dates, TRUE/FALSE, decimal numbers (19.90);
- lists where a cell would go over 32,767 characters, the maximum of an Excel cell.
Common mistakes
- Enter confirms the cell instead of adding a line: enter the cell first, then use your spreadsheet's shortcut.
- The values look stuck on a single line: in Excel, turn on “Wrap Text” (Home tab). The values are on separate lines, the display just folds them. In the Excel file (.xlsx) of the transformation, list cells are already formatted to show one value per line.
- Commas or semicolons between values separate nothing: only the line break does. “red, blue” in a cell would give a single tag.
- A list kept its numbered columns: it is one of the cases in the previous section. Numbered columns are edited the same way, and an emptied cell writes no tag.
Drop your XML file to try it: the preview is free and needs no account, nothing is charged without your confirmation:
Transform a file