5

I have a rails application that exports content from my database in an xls format.

I'm looking to create two separate tables without putting them in the same row. Is there anyway to have two index's on the same row?

<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  xmlns:html="http://www.w3.org/TR/REC-html40">
<ss:Worksheet ss:Name="Sheet">
    <Table>
    <% @data.each do |data| %>
        <Row ss:Index="1">
            <Cell ss:Index="1"><Data ss:Type="String"><%= data.name %></Data></Cell>
        </Row>
    <% end %>
    <% @moreData.each do |moreData| %>
        <Row ss:Index="1">
            <Cell ss:Index="2"><Data ss:Type="String"><%= moreData.name %></Data></Cell>
        </Row>
    <% end %>
    </Table>
</ss:Worksheet>
</Workbook>

This is what I have with the above code:

enter image description here

And this is what I'm trying to achieve if possible without putting both loops in the same row:

enter image description here

Shrikant
  • 523
  • 4
  • 15
DollarChills
  • 1,076
  • 1
  • 15
  • 33
  • I'm not sure I understand. It looks like you want both items in the same row, but you say you don't want them in the same row. Is this something you can actually do with a spreadsheet when just editing by hand in Excel? – Phil Dec 04 '17 at 15:57

1 Answers1

3

Maybe use .zip on the data?

ex.

<Row ss:Index="1">
    <% @data.zip(@moreData).each do |d, md| %>
        <Cell ss:Index="1"><Data ss:Type="String"><%= d.name %></Data></Cell>
        <Cell ss:Index="2"><Data ss:Type="String"><%= md.name %></Data></Cell>
    <% end %>
</Row>
Tomasz Giba
  • 507
  • 1
  • 8
  • 22