roo-rb / roo

Roo provides an interface to spreadsheets of several sorts.
MIT License
2.78k stars 503 forks source link

roo error when open .xlsx in microsoft office #404

Open luis77 opened 6 years ago

luis77 commented 6 years ago

I am exporting records using the gem roo in .xlsx format and I am opening them in free office and opens without any error but when I try to open the same file using microsoft office in windows it sends me the following error "Excel can not open the clients.xlsx file because the format or extension of this is not valid, check that the file has not been damaged and that the file extension matches the file format". If for example I open the file in free office and apply in "save as" and then in format put "xlsx" with it does not show the error in windows, but with the one that generates me roo gives me the error.

this is my mime_types.rb

Mime::Type.register "application/xls", :xls
Mime::Type.register "application/xlsx", :xlsx

my roo gems:

gem "roo"
gem "iconv"
gem "roo-xls"

my index.xlsx.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="Cliente">
     <Interior ss:Color="#6FC9FF" ss:Pattern="Solid"/>
    </Style>
    <Style ss:ID="Listas">
    <Interior ss:Color="#89acfe" ss:Pattern="Solid"/>
    </Style>
    <Style ss:ID="Ruta">
      <Interior ss:Color="#b29ef4" ss:Pattern="Solid"/>
    </Style>

  </Styles>

  <Worksheet ss:Name="Sheet1">
    <Table>
      <Row>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Clave</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Encargado</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Nombre Comercial</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Calle y N°</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">C.P</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Colonia</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Latitud</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Longitud</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Referencia</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Activo</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Teléfono</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Tel. Celular</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Email</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Horario</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Credito</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Limite Credito</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Días Credito</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Saldo inicial</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Visita Obligada</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Firma Obligada</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Clase 1</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Clase 2</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Clase 3</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Clase 4</Data></Cell>
        <Cell ss:StyleID="Cliente"><Data ss:Type="String">Clase 5</Data></Cell>
        <Cell ss:StyleID="Listas"><Data ss:Type="String">Lista de Precio</Data></Cell>
        <Cell ss:StyleID="Listas"><Data ss:Type="String">Lista de Descuento</Data></Cell>
        <Cell ss:StyleID="Listas"><Data ss:Type="String">Lista de Promociones</Data></Cell>
        <Cell ss:StyleID="Ruta"><Data ss:Type="String">Ruta(numero de ruta)</Data></Cell>
        <Cell ss:StyleID="Ruta"><Data ss:Type="String">Vendedor(clave)</Data></Cell>
        <Cell ss:StyleID="Ruta"><Data ss:Type="String">Lunes</Data></Cell>
        <Cell ss:StyleID="Ruta"><Data ss:Type="String">Martes</Data></Cell>
        <Cell ss:StyleID="Ruta"><Data ss:Type="String">Miércoles</Data></Cell>
        <Cell ss:StyleID="Ruta"><Data ss:Type="String">Jueves</Data></Cell>
        <Cell ss:StyleID="Ruta"><Data ss:Type="String">Viernes</Data></Cell>
        <Cell ss:StyleID="Ruta"><Data ss:Type="String">Sábado</Data></Cell>
        <Cell ss:StyleID="Ruta"><Data ss:Type="String">Domingo</Data></Cell>

      </Row>

      <% @clientesExp.each do |cliente| %>
        <Row>
          <Cell><Data ss:Type="String"><%= cliente.try(:IdCli)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Nombre)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:NombreCorto)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Direccion)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:CP)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Colonia)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Latitud)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Longitud)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Referencia)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Status)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Telefono)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Tel2)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Email)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Horario)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Credito)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:LimiteCredito)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:DiasCreedito)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Saldo)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:VisitaObligada)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:FirmaObligada)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Clas1) %></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Clas2) %></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Clas3) %></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Clas4) %></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Clas5) %></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.relclili.try(:ListaP)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.relclili.try(:ListaD)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.relclili.try(:ListaPromo)%></Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Ruta) %> </Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Vendedor) %> </Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Lunes) %> </Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Martes) %> </Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Miercoles) %> </Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Jueves) %> </Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Viernes) %> </Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Sabado) %> </Data></Cell>
          <Cell><Data ss:Type="String"><%= cliente.try(:Domingo) %> </Data></Cell>
        </Row>
      <%end%>

    </Table>
  </Worksheet>
</Workbook>

my index action:

  def index

    @clientesExp = Cliente.all
    respond_to do |format|
      format.html
      format.csv { send_data @clientesExp.to_csv}
      format.xlsx #{ send_data @empresas.to_csv(col_sep: "\t") }
      format.js
    end
  end
mityakoval commented 6 years ago

Hi!

Were you able to fix this?

rajanverma-me commented 6 years ago

any solution??

tgturner commented 5 years ago

@luis77 I feel like I might be missing where Roo comes into play here. Where does your format.xlsx use roo? It looks to me like you are just using an erb template that you created. Am I missing something?