Guest User

Untitled

a guest
May 27th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. # exemplo de geração de arquivo XLS com biblioteca CSV e TAB como caractere
  2. # de separação de campos. Importante usar quebra de linha no formato DOS (CR+LF)
  3.  
  4. require 'csv'
  5. EOL = "\r\n"
  6.  
  7. plan = File.open('arquivo.xls', 'w')
  8.  
  9. # cabeçalho
  10. plan << CSV.generate_line(["NOME","SOBRENOME","DATA","SALDO"], "\t") << EOL
  11.  
  12. # dados da tabela
  13. plan << CSV.generate_line(["FULANO", "DE TAL", "31/12/2008", "2500,00"], "\t") << EOL
  14. plan << CSV.generate_line(["JOSE", "DA SILVA", "31/10/2008", "3400,00"], "\t") << EOL
  15. plan << CSV.generate_line(["JOHN", "DOE", "30/11/2008", "4500,00"], "\t") << EOL
  16.  
  17. # ok, fecha o arquivo
  18. plan.close
Add Comment
Please, Sign In to add comment