我看到这篇文章,它提供了一个简单的示例,介绍如何在 Rails 中不使用任何 gem 将数据导出到 Excel 工作表:
https://makandracards.com/makandra/31567-exporting-to-excel-from-rails-without-a-gem
我相信上述文章基于同一主题的 RailsCast 教程:
http://railscasts.com/episodes/362-exporting-csv-and-excel?view=asciicast
我想知道如何包含背景颜色和行边框(以及边框颜色)。请帮忙!
最佳答案
如果您使用“手动”XML 方法,一个好的开始方法是官方 Microsoft XML Spreadsheet Reference .
有很多可用选项,例如带边框的文档可能看起来像这样。
<?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">
<Styles>
<Style ss:ID="h1" ss:Name="First">
<Borders>
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
</Style>
</Styles>
<Worksheet ss:Name="Sheet1">
<Table>
<Row>
<Cell ss:StyleID="h1"><Data ss:Type="String">ID</Data></Cell>
<Cell ss:StyleID="h1"><Data ss:Type="String">Name</Data></Cell>
<Cell ss:StyleID="h1"><Data ss:Type="String">Release Date</Data> </Cell>
<Cell ss:StyleID="h1"><Data ss:Type="String">Price</Data></Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
您可以在工作簿部分的开头定义不同的样式,然后将它们应用到不同的单元格。
关于ruby-on-rails - 如何在导出 Excel 时包含背景颜色而不在 Rails 中添加任何 Gem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53202441/