如果用 spreadsheet_architect 导出这样的表格
合并单元格?
merges: [
{range: "A1:C1"},
{range: {rows: 2, columns: :all}},
{range: {rows: (3..4), columns: (0..3)}}
],
分享个古早的技巧,使用 XML Spreadsheet,写起来跟 HTML 模板类似,可读性好,也可以支持定制单元格合并以及样式等,但不确定最新版 Office 还有没有保持兼容。
<?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">
<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<Cell><Data ss:Type="String">ID</Data></Cell>
<Cell><Data ss:Type="String">Name</Data></Cell>
<Cell><Data ss:Type="String">Release Date</Data></Cell>
<Cell><Data ss:Type="String">Price</Data></Cell>
</Row>
<% @products.each do |product| %>
<Row>
<Cell><Data ss:Type="Number"><%= product.id %></Data></Cell>
<Cell><Data ss:Type="String"><%= product.name %></Data></Cell>
<Cell><Data ss:Type="String"><%= product.released_on %></Data></Cell>
<Cell><Data ss:Type="Number"><%= product.price %></Data></Cell>
</Row>
<% end %>
</Table>
</Worksheet>
</Workbook>
RailsCast 上有教程,我几年前还在 Shopee 用这个东西实现比较复杂的 Excel 样式。 http://railscasts.com/episodes/362-exporting-csv-and-excel?view=asciicast https://learn.microsoft.com/en-us/previous-versions/office/developer/office-xp/aa140066v=office.10)?redirectedfrom=MSDN(