Suppose I have many objects, each has a UID property and an array of credit card NOs card_nos.
I want to dump the information to CVS(Excel) file in a fashion that cells with same UID are merged to form a single one. One UID spans as many rows as the number of credit cards it has, but at least one.
Here is an example, User 001 has 3 cards, so the cvs file will look like the following:
+-------------+
| UID | Card# |
--------------+
| | Card1 |
--------+
| 001 | Card2 |
--------+
| | Card3 |
--------------+
Any ideas? Thanks in advance.
You can’t create a CSV file that does this – the CSV format doesn’t support it.
Try it the other way and you’ll see: create a worksheet with the formatting as you describe and save it as CSV. You’ll get a warning starting with
Accept the limitation and you’ll get a CSV file. Mine looked like this:
… which, when I reloaded it into Excel had indeed lost the merge as I expected:
You can, however, get there with HTML, if it makes sense otherwise in your app – the following HTML will load with a merged UID cell as described (note the use of the “
rowspan” attribute):