I assume that's because you sending just a template. But you should construct a table first.
I don't know what data type is your @like_list
is, but let's say it is a Hash.
In that case you should build your attachment. Here is just an example that shows the basic approach:
# mailer
def table_deliver
to = "user@example.com"
from = "no-reply@example.com"
subject = "Foo"
@company = "Ggl"
@like_list = { foo: 1,
bar: 2,
baz: 3 }
attachments["#{@company}likelist.xls"] = build_table(@like_list)
@body = "Mail body"
mail(to: to, from: from, subject: subject)
end
private
def build_table(data)
opts = OpenStruct.new(data)
template = ERB.new(File.read("#{Rails.root}/app/views/products/like_list.xls.erb"))
template.result(opts.instance_eval { binding })
end
# template
<table>
<thead>
<th>foo</th>
<th>bar</th>
</thead>
<tbody>
<% data.each do |k, v| %>
<tr>
<td><%= k %></td>
<td><%= v %></td>
</tr>
<% end %>
</tbody>
</table>
And the result in letter_opener:

Attachment opened in libre office

Hope that helps and feel free to ask some additional questions.
UPDATE
First you create an OpenStruct from your Hash params. Then create a new ERB class instance.
result
is a method of ERB class, that applies params to existing template.
binding
is an object that provides access to the instance methods and variables that are owned by another object.
More info here
instance_eval
is a Object method that evaluates a string containing Ruby source code, or the given block, within the context of the receiver (obj).
More info here
So, that code do the following
- creates some struct with key-value pairs
- creates new template
- executes
binding
object in context of template and assigns key-value pairs to the template.
You could refer to this SO post for more details