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

16,181

Solution 1

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

Solution 2

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

Share:
16,181
Andy
Author by

Andy

Updated on June 14, 2022

Comments

  • Andy
    Andy almost 2 years

    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