Is it possible to export to CSV and have the header contain spaces?

依然范特西╮ 提交于 2019-12-08 16:42:13

问题


I have a requirement for an SSRS 2005 report to be exported as a CSV, where the column headers contain spaces.

Currently the CSV header column titles are derived from the textBox property names and uses underscores instead of spaces. Is there another, better approach?

For example, currently I have:

  • SSRS Report Header : Effective Date
  • TextBox Name : Effective_Date
  • CSV Header: Effective_Date

I would like to have:

  • SSRS Report Header : Effective Date
  • TextBox Name : Effective_Date
  • CSV Header: Effective Date

回答1:


Looks like its not possible, with a bit more digging I found the following Stack Overflow post:

  • SSRS csv export with comma in the column header names



回答2:


There is a solution for this. You need to select in SSRS properties press F4, select Properties, in that select particular textbox which you want to rename. For example, let Textbox12 as a Effective_Date. Solution: Rename the Textbox with EffectiveDate.




回答3:


I have solved this problem myself by customizing the built in CSV rendering extension to make it use the textbox's ToolTip property as the column header. The ToolTip property will allow spaces and other punctuation so gives you the flexibility to name the columns as you like. This also has the nice side effect of giving you a relevant tool tip, reminding you of what column you're looking at on a long report where the header might not be visible!

Note: In the designer, you set the ToolTip of the data row's textbox and not the header's textbox.

This isn't easily achieved because all the rendering extensions are marked as sealed classes. So to implement this, I used a decompiler and extracted all the code relating to CSV rendering into my own project. Then changed the line that writes the header text to read from the textbox's ToolTip property instead.

In the class named CsvColumnHeaderHandler you're looking for the method OnTextBoxBegin and in particular the line:

this.m_visitor.WriteValue(textBox.DataElementName, this.m_excelMode);

Simply change this to read:

this.m_visitor.WriteValue(textBox.ToolTip, this.m_excelMode);

This custom rendering extension can then be deployed to the report server and it works perfectly.

You wont need to know how to write a rendering extension for this because, as I said, I just copied (decompiled) the code. However, you will need to know how to deploy a custom rendering extension assembly. More information on deploying can be found here: https://msdn.microsoft.com/en-us/library/ms154516.aspx



来源:https://stackoverflow.com/questions/14156985/is-it-possible-to-export-to-csv-and-have-the-header-contain-spaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!