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

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

  • 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

  • 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.


    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

    链接地址: http://www.djcxy.com/p/68172.html

    上一篇: 如何整合这两个?

    下一篇: 是否可以导出为CSV并且标题包含空格?