SSRS csv export with comma in the column header names - reporting-services

By default, csv takes the text box name as the csv header name for the columns. The text box does not allow a space.
How do I make a different header than the text box for the csv?
Is there a way to display comma in the header when exported to csv?
Note: The solution has to be only for one report; not global.

The column name comes from the DataElementName property, or if that is blank, the Name property. Unfortunatly, neither allow commas or quoting.
There is a blog post here:
http://www.behindthecode.net/Blog/post/2008/01/29/How-to-modify-Reporting-Services-CSV-export-Behavior.aspx
on how to change settings in the config file for csv exports. These are global changes. The list of properties available is here:
http://msdn.microsoft.com/en-us/library/ms155365.aspx
None of these allow the spaces you need, or the quoting of column names that I am currently trying to achieve. Sorry.

In short, No, it's not possible.
From SSRS 2008 Column issue when exporting to a CSV file:
For csv export, the header of a column is determined by the DataElementName property of the textbox which actually contains the data. If the DataElementName property is not explicitly set by the user, DataElementName automatically gets defaulted to the value of the textbox.Name property.
That being said, I believe you're getting this issue because RDL has a restriction that both a reportItem.Name and reportItem.DataElementName property must be CLS-compliant identifiers. The headings like "Phone #", "Other Name(s)", etc... are not CLS-Compliant.
You can verify this by opening up the report in BIDS or RB and trying to set the DataElementName/Name property of the textbox containing the data to those names.
You will get an error which states the following:
Property Value is not valid. Specify a valid name. The name cannot contain spaces, and it must begin with a letter followed by letters, numbers, or the underscore character (_).
There is a Microsoft Connect Issue about this, but unfortunately it looks like it won't be acted on.
See: Use of expressions for DataElementName property (for CSV Export)

This solution works: https://stackoverflow.com/a/32110072/674237
In summary:
Modify your query to have the first row in the data set be your desired column headers. E.g., select header names and union them to the data set.
Add a new CSV rendering extension to the report server that excludes headers.
This workaround will let you to put whatever values you'd like in the headers.

Append the following query parameters to your url:
For # - [url]&rs:format=CSV&rc:FieldDelimiter=%23
For ; - [url]&rs:format=CSV&rc:FieldDelimiter=";"
Not sure you can do it directly from Report Manager without altering config files somewhere
Update: After rereading this, are you returning the column headers from the procedure like this?
SELECT tbl.colname [my column name, some text],
tbl.col2 [another, col]
The square brackets will allow you to escape characters.

Column names for Csv, Dbf and Xml are picked up from <Name> field by default.
Solved this issue by adding appropriate names for each of this formats in <Tag> field in *.mrt file. E.g:
<Name>Txt_InternalName</Name>
<Tag>CSV:"Name for Csv"; DBF: "Name for DBF"; XML: "Name for Xml"; Default: "Default Name for Csv Dbf Xml"</Tag>
Also it resolves issue with CLS non compliant identifiers in headers

Related

Issues exporting SSRS to CSV with textbox names

So I'm trying to export my SSRS to .CSV. The layout of my report is like this:
Everything does work fine, on my VS. However, when comes the time to generate it I get this:
I've read a few other post on Stack Overflow about how I can change my SSRS config for noheaders and ASCII. Thing is, people tried to set column names programatically, but here I only have expressions for cell contents and a current layout. Is there a way to make my CSV lay out look like my reportbuilder layout? Or is my problem the same as when people try to set the column programatically
For each data field you want to export set the DataElementName to match the field title and set the value to the DataElementOutput to output the field.
For the header textboxes set the DataElementOutput to NoOutput.
For more detail check the following microsoft link
https://msdn.microsoft.com/en-us/library/dd255251.aspx

How to customize the header of the CSV file that exported by a SSRS report

I have created an SSRS report and exported that to a CSV file. The header of that CSV file displays an odd name "Donations_Chart1_CategoryGroup_label".
I want to customize the name. If any one have an idea about that please let me know the solution.
The name of the header is taken from the DataElementName property, which can be set in the Properties Window, under "Data Only".
If it is not specified, the Name property is taken, it is autogenerated unless you change it, which explains your "odd name".
So you could either change the Name or the DataElementName of the element.

Formatting of exported SSRS report to CSV file

My 2008R2 SSRS report contains a detail column called debit which is formatted like "#,0.00". When I export the file via .csv the debit column does not always have the right formatting of 0.00. If the number is 0, then what appears is "0". If the number is 123.40, then it appears as 123.4. If the number is 123.44, then it appears as 1213.44.
I want each number in this column to always have 2 decimal places in the .csv file. I checked out many other articles on stackoverflow about this, but none seem to address this issue correctly.
I tried changing the format to many other formats. I noticed when I changed the format in SSRS to "C" for currency, then the 2 decimal places appeared. But the problem with that is my users do not want the "$" symbol.
I tried changing the CSV export to ASCII format in the config file, but that did not work.
I used the code here:Non-Unicode CSV Export from SQL Server Report Server
Can anyone help me with getting the format correct in the CSV file without mannually changing the CSV file?
Thank you!
The problem mentioned is report header's are being displayed when user generate report for CSV format, which is not supposed to be like that. But actually in CSV Format, While in the preview , we can hide or show report header's and it doesn't show textbox names .
While in the exported/generated one , the CSV format hides the report's headers, but instead of that it shows textbox names and any changes We made in the properties to change that textbox name to make it as blank or disappear, it reflects on that column values but doesn't on that textbox name.
So I want to mention that better We can give some other meaningful names or by default it shows as 'Textbox1', but we must give any valid name to that textbox name and it appears on the generated CSV format.
NOTE: I also want to mention that all visibility properties works well with the report header's but not on the textbox names.

Column Visibility when Exporting to CSV

Can someone tell me why this doesn't work?
I have the "Column Visibility" set to "Show or hide based on an expression"
The expression is the following:
=IIF(Globals!RenderFormat.Name = "CSV",True,False)
Save to CSV, Column shows.
Format options such as expressions on visibility are ignored for CSV rendering methods. CSV rendering methods are essentially data flows, so you can suppress elements that you don't want to include in CSV files by changing the DataElementOutput from Auto, the default value, to NoOutput.

Have SSIS detect the column sizes of a csv file

I'm trying to import a csv file into SQL using SSIS and am hitting a fundamental flaw.
SSIS seems to determine that all fields are varchar(50), even though it correctly identifies the comma delimiter.
This is causing issues when I try to send the data to my table in SQL.
Is there a way of making it recognise that a field of length 3 is actually a field of length 3, and not 50?
Thanks
Yes, there's a Suggest Types function in the Flat File Connection Manager Editor.
Assume you have got a CSV file shown in the first image.
Create a new Flat file connection, and browse this file on your computer. The Columns tab shows the sample of the file.
Click Advanced tab. There you can see all columns have DT_STR type with the length of 50. What you can see is the Suggest Types... button. Click this.
Set parameters as you like. Defaults are all right in my case. Click OK.
Now the first column has the type of DT_STR with the length of 1. (The other two columns have got new types as well. The Number column got DT_I1 (because we choosed the smallest appropriate integer type option), and the Date column got DT_DATE.