How to include background colors while exporting excel without any gems in rails?

I saw this article which gives a simple example on how to export data into Excel sheet without using any gem in Rails:

I believe the above article is based on a RailsCast tutorial on the same topic:

I would like to know how to include background colors and row borders (and also border colors) please. Please help!

1 answer

  • answered 2018-11-08 06:47 mkrl

    If you are using the "manual" XML approach, a good way to start is an official Microsoft XML Spreadsheet Reference.

    There are many options available, for example a document with borders may look something like this.

    <?xml version="1.0"?>
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
          <Style ss:ID="h1" ss:Name="First">
              <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"/>
      <Worksheet ss:Name="Sheet1">
            <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>

    You can define different styles at the beginning of the workbook section and then apply them to different cells.