0

I used this template using cell styles:

show_xls.xls.erb

<?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><Data ss:StyleId="h1" ss:Type="String">ID</Data></Cell>
        <Cell><Data ss:StyleId="h1" ss:Type="String">Name</Data></Cell>
        <Cell><Data ss:StyleId="h1" ss:Type="String">Release Date</Data>    </Cell>
        <Cell><Data ss:StyleId="h1" ss:Type="String">Price</Data></Cell>
      </Row>
    </Table>
  </Worksheet>
</Workbook>

This is my controller function:

forecast_controller.rb

def show_xls
  respond_to do |format|
    format.html
    format.xls
  end
end

This is my route:

routes.rb

get "forecast/show_xls" => "forecast#show_xls", as: :forecast_report_excel

This is my button which generates excel when clicked:

<%= link_to 'Generate Excel',forecast_report_excel_path(format: :xls), class: 'btn btn-primary' %>

I get a spreadsheet all right but the cell styles don't get applied.

This is the spreadsheet that gets generated for me:

enter image description here

Why aren't my styles getting applied in the spreadsheet? What am I doing wrong? Please help!

Biju
  • 820
  • 1
  • 11
  • 34

0 Answers0