Redmineの時間トラッキングレポートの文字化けの対処法

RedmineCSVレポートの文字コードについては、基本的には http://redmine.jp/faq/general/pdfcsv/ で対処できる。

ただし時間トラッキングレポートの左下の「合計」という文字だけはどうしても化ける。

ここを表示するソースは app/helpers/timelog_helper.rb の以下のメソッド(0.8.7)。

  def report_to_csv(criterias, periods, hours)
    export = StringIO.new
    CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
      # Column headers
      headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
      headers += periods
      headers << l(:label_total)
      csv << headers.collect {|c| to_utf8(c) }
      # Content
      report_criteria_to_csv(csv, criterias, periods, hours)
      # Total row
      row = [ l(:label_total) ] + [''] * (criterias.size - 1)
      total = 0
      periods.each do |period|
        sum = sum_hours(select_hours(hours, @columns, period.to_s))
        total += sum
        row << (sum > 0 ? "%.2f" % sum : '')
      end
      row << "%.2f" %total
      csv << row
    end
    export.rewind
    export
  end

ヘッダ(headers変数) は to_utf8 で文字コード変換しているのに、最後の行(row変数)は変換していない。
そこでrowも文字変換してみる。

  def report_to_csv(criterias, periods, hours)
    export = StringIO.new
    CSV::Writer.generate(export, l(:general_csv_separator)) do |csv|
      # Column headers
      headers = criterias.collect {|criteria| l(@available_criterias[criteria][:label]) }
      headers += periods
      headers << l(:label_total)
      csv << headers.collect {|c| to_utf8(c) }
      # Content
      report_criteria_to_csv(csv, criterias, periods, hours)
      # Total row
      row = [ l(:label_total) ] + [''] * (criterias.size - 1)
      total = 0
      periods.each do |period|
        sum = sum_hours(select_hours(hours, @columns, period.to_s))
        total += sum
        row << (sum > 0 ? "%.2f" % sum : '')
      end
      row << "%.2f" %total
      row1 = row.collect {|c| to_utf8(c) }
      csv << row1
    end
    export.rewind
    export
  end

結果

なおった!!

先端を確認していないので、もしかしたら開発版はなおっているのかもしれない。



入門Redmine Linux/Windows対応
前田 剛
秀和システム
売り上げランキング: 112182