I'm creating one CSV file using csv_table_view(Code copied below). I want to prefix CSV data with some text message. This message should be in red color and bold. Is there any way by which I can specify text color and bold property in the message string. Here is my code-
def render_csv(view)
ctv = CsvTableView.new(view)
csv = ctv.render
render_csv_content(csv, ctv)
end
def render_csv_content(csv, ctv)
headers['Content-Type'] = "application/vnd.ms-excel"
headers['Content-Length'] = csv.size
headers['Cache-Control'] = ''
headers['Content-Disposition'] = %{attachment; filename="#{ctv.filename}"; size=#{csv.size}}
render :text => csv
end
def render
@table.prepare(true)
@ret = []
@ret ="Hello this message should be red and bold \n"
@ret += @table.columns.map do |col|
col.split ? col.split.map { |c| "#{col.name} #{c}" }.join(",") : csv_escape(col.name)
end.join(",") + "\n" +
@table.all_rows.map { |row| row.map { |col| csv_escape(col)
}.join(",") }.join("\n")
end
I read in one article that with content type application/vnd.ms-excel, we can not add formatting to the text. Any idea on that? Thanks in advance.