Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

csv.rb 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # encoding: utf-8
  2. #
  3. # Redmine - project management software
  4. # Copyright (C) 2006-2017 Jean-Philippe Lang
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. require 'csv'
  20. module Redmine
  21. module Export
  22. module CSV
  23. def self.generate(*args, &block)
  24. Base.generate(*args, &block)
  25. end
  26. class Base < ::CSV
  27. include Redmine::I18n
  28. class << self
  29. def generate(options = {}, &block)
  30. col_sep = l(:general_csv_separator)
  31. encoding = Encoding.find(options[:encoding]) rescue Encoding.find(l(:general_csv_encoding))
  32. str = ''.force_encoding(encoding)
  33. if encoding == Encoding::UTF_8
  34. # BOM
  35. str = "\xEF\xBB\xBF".force_encoding(encoding)
  36. end
  37. super(str, :col_sep => col_sep, :encoding => encoding, &block)
  38. end
  39. end
  40. def <<(row)
  41. row = row.map do |field|
  42. case field
  43. when String
  44. Redmine::CodesetUtil.from_utf8(field, self.encoding.name)
  45. when Float
  46. @decimal_separator ||= l(:general_csv_decimal_separator)
  47. ("%.2f" % field).gsub('.', @decimal_separator)
  48. else
  49. field
  50. end
  51. end
  52. super row
  53. end
  54. end
  55. end
  56. end
  57. end