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

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

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

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.

Related

SSRS Possible to toggle Header visibility based on export type? 2008-R2

I'm familiar with dynamically showing/hiding other report objects (textboxes/tablix/columns etc...) based on a variable or parameter value - but is there a way to do this with the header? I don't see any "visibility" tab on the header object to set an expression.
Further more, is there a way to do hide the header based on the export style. For example, I want to show the header when exported to PDF, but want to hide it when exporting to XLS (to prevent cell merging).
I've seen examples of when the "header" is replaced by a "rectangle" which can be toggled. I've also seen articles refering to =Globals!RenderFormat.IsInteractive = “EXCEL”), but I don't know where that is set? On a server config file? Is there a way to have it done just for that one specific rdl report file?
Thanks in advance!
Answering your questions:
Is there way to dynamically show/hide the header - no. Unfortunately, you can't set visibility for whole header/footer in RDL reports.
Is there way to hide the header based on the export style - not quite. As I stated, you can't set visibility for whole header, but you can set visibility for separate report items in header based on the export style.
Where that is set - it is set in report, in usual Hidden expressions. There is nothing to do with server config file to achieve this (the only point is to take a look at rsreportserver.config - it contains section with rendering extensions, it's useful to know their names, f.e. name "EXCEL" is for old binary XLS format, while "EXCELOPENXML" is for modern XLSX).
To set visibility based on the export style, you can use built-in report field RenderFormat.Name (notice that it is Name, not IsInteractive!). Just type the following expression for the Hidden property:
=Globals!RenderFormat.Name = "PDF"
In conclusion, you can't set visibility for whole header, you can show/hide report items inside header based on different conditions you want, but header will still take some place. To really hide the header so it will not consume the space of report, you can simulate the header with rectangle and page breaks, this is the workaround.
The report requirement I had before me was of similar nature.
NEED: Hide the headers when exported to CSV file.
The report is going to be exported to CSV and then uploaded into another system (a system that doesn't want headers). To be more user-friendly, I wanted the report to show the headers but not export them in the CSV file.
I tried some things that did not work. Then I found an article describing how you can create a new export format, Labeled: "CSV No Headers", which solved the export requirement.
SOLUTION: rsreportserver.config
FILE: D:\Program Files\Microsoft SQL Server\MSRS13.MSSQLSERVER\Reporting Services\ReportServer\rsreportserver.config
XML:
<Extension Name="CSV (No Header)" Type="Microsoft.ReportingServices.Rendering.DataRenderer.CsvReport,Microsoft.ReportingServices.DataRendering">
<OverrideNames>
<Name Language="en-us"> CSV No Header</Name>
</OverrideNames>
<Configuration>
<DeviceInfo>
<NoHeader>true</NoHeader>
</DeviceInfo>
</Configuration>
SOLUTION DEMO
NEW OPTION:
EXPORTED> Report Name (CSV No Header).csv:
EXPORTED> Report Name (Excel).xlsx:
SOURCE: Charanmandya Blogspot: Export Csv Without Header in SSRS
Things that did not work...
I read through this article, Blog, Beer Intelligence by Valentino Vranken: "Hide/Show Items Dependant On Export Format (SSRS)". The article was helpful with lots of user comments and suggestions. But I tried these things but they did not work for CSV export without header row.
Row Visibility > Expression > =Globals!RenderFormat.Name = "CSV"
This worked for "Excel" or "EXCELOPENXML" format. For some reason "CSV" does not work.
Select Row> Properties: Data Only> [Data Element Output=NoOutput]
Some related stackoverflow questions...
SSRS Export to pipe delimited file loose its headers
Exporting from SSRS to Excel with no headers

SSRS - embed URL and formatting characters in parameter

I'm making a form letter in SSRS 2012 that will be delivered by email. I had it working fine but now the powers that be have requested a much more dynamic aspect to it based on the individual recipient... Different paragraphs now need to be included/excluded based on the target.
With that, I pulled the body of the email out of SSRS and am now assembling it in SQL Server and passing it over to SSRS as a parameter (so that I don't wind up making a dozen SSRS reports to handle the need).
I have that part working too now, but hit a snag... There were a few bullet points as well as URL's that could look nicer. I'd like to force an indention before the bullet points and replace www.mysite.com with something prettier like "Click Here". On the SSRS side of the fence, I currently just have a single text box (and ideally would keep it that way) which contains an expression that references my "EmailBody" parameter.
So far, I have not found the right combination of words to send to Google to see if this is possible, so I figured I'd go straight to the pros here. I did try formatting the output in a similar manner to what an expression would look like ( ="This is the body of my email" ) and it just passed that straight on through to the final output.
Any ideas would be appreciated!
Jason
In case it helps anyone else, I figured out the secret.
Change your text box in SSRS to expect HTML by right-clicking on the placeholder (<< EXP >>) inside the text box, selecting Placeholder Properties, and change the Markup Type to "HTML - Interpret HTML tags as styles".
After that, go back to the SQL Server side of the fence and change the text you are sending as a parameter to HTML with whatever styling properties you desire.
Sounds like you're on the right track with the HTML markup. I also wanted to suggest that you can use a data-driven subscription. Have the query generate the HTML you want. Then have that populate the body of the email. That way there's no need for any attachments. This has come in handy when I wanted to display a small table of data for viewing on a mobile device rather than having to open an Excel attachment.

How to use ReportItem property(ReportItems!TextboxName.Value) in body of SSRS report

I'm working on SSRS Report using report builder and want to get a value of a textbox of table using (ReportItems!textboxName.Value). Can I do this? After searching on internet i found that i Cant use it in report's body(may be i'm wrong) than how I can get the value of specific textbox of table?
Yes that should be valid, here is a link to the specific technet article on the topic.
The basic format is something along the lines of:
=ReportItems!Textbox1.Value + ReportItems!Textbox2.Value
There are a couple of restrictions on it because of when it would be generated, but it shouldn't have a problem being in the body.

Formatting numbers in SSRS

How i can format values in SSRS in this format
"_(* #,##0.00_);_(* (#,##0.00);_(* -?_);_(#_)"
This is Excel formatting style, but how to make the same in SSRS
If you go to properties for the textbox, copy and paste the string into the Format field.
If this does not give the desired results, please describe the difference in the question.
You can define custom format in SSRS by navigating to place holder properties of particular field, and then navigating to 'number' tab. In category section we have option to defined our custom number format. so you can define your custom format there.

Creating custom SSRS handler for field with HTML

I have an SSRS 2008 report with a field that contains and is configured to render as HTML. Some of the text in this field may contain IMG tags, and the IMG tag is not among the tags SSRS natively supports within its HTML rendering extension.
I am trying to find a way to write a custom handler to hook into the processing of this field that will let me look at the raw HTML before the SSRS handler processes it, in the hopes of grabbing IMG tags, extracting the SRC URL and getting the raw bytes of an image to insert on the fly in a way SSRS will accept, yet retaining the HTML SSRS will render.
From what I've read and seen so far, if a field is marked to render as HTML, the SSRS processor grabs it and parses it entirely before any handler could modify it, meaning the IMG tag is (would be) discarded before I could do anything with it (or even know it was present). The only option I see is to turn off the HTML rendering entirely, thus losing the benefit of the tags SSRS can recognize.
EDIT: Per Jamie's response below, I'm beginning to think the "2nd half" of this issue may prove harder than I realized: Is it even possible to programmatically add an Image to an SSRS Report at runtime (obviously through code/custom assembly)? That is, I'd like to write some code that might look something like this (pseudocode)
'Conceptual Pseudocode I'd like to be able to write
'for dynamic addition of Image element in SSRS report
'Is this even possible?? Is there a documented Report
'object model??
Public Function AddImage(imageBytes() as Byte) as Image
Dim newImage as New Image()
newImage.SetBytes(imageBytes)
Report.Add(newImage)
return newImage
End Function
I'm hoping I'm just overlooking something simple that prevents me from grabbing the raw, unprocessed HTML, and someone else might be able to point me in the right direction on how to grab it.
EDIT: I have created and implemented this solution within the SSRS development environment and it works. WOOHOO :) It did require some hoop-jumping with creating a Single-Threaded Apartment thread to host the WebBrowser control, and to create a message pump, but it does work! **
As I was literally typing up the message to a co-worker that this issue was a non-starter, I did have a bit of an inspiration on a way to solve this problem. I know this post hasn't generated a great deal of response, but just in case someone else finds themselves in a similar problem, I'm going to share what I've implemented in a "petri dish" scenario that, provided I get all the code permission issues resolved, should allow me a decent solution to this problem.
With SSRS inability to handle an IMG tag insurmountable, I actually thought of an idea that took the HTML rendering away from SSRS entirely. To do this, I created custom code that hands off the HTML rendering to a WebBrowser control, then copies the rendered result as an image. It does the following:
Instantiates a WebBrowser control of a given width and height.
Sets the DocumentText property of that control to the HTML from TinyMCE
Waits for the DocumentText to completely render.
Creates a bitmap equal to the size of the control.
Uses the undocumented and presumably unsupported DrawToBitmap method of the WebBrowser to draw the rendered HTML to a bitmap.
Copies the Bitmap to an Image
Saves the Image as a .png file
Returns the path to the .png as the result of the function.
In SSRS, I plan to replace the erstwhile HTML text field with an external Image control that will then call the above method and render the image file. I may alter that to simply draw the image to the SSRS Image control directly, but that's a final detail I'll resolve later. I think this basic design is going to work. Its a little kludgey, but I think it will work.
I have some permissions issues to work out with the code that SSRS will allow me to call at runtime, but I'm confident I'll get those sorted out (even if I end up moving the code to a separate assembly). Once this is tested and working, I plan to mark this as the answer.
Thanks to those who offered suggestions.
I've done something similar with success: We had an HTML "Comment" field that was collected on a web form. For a particular report we wanted to truncate this field to the first 1000 characters or so, but preserve valid HTML.
So I created a C# .dll & class with a public function:
public static string TruncateHtml(string html, int characters)
{
...
}
(I used the HtmlAgilityPack for most of the HTML parsing, and to create and close off my new HTML string, while I kept track of the content length.)
Then I could call that code with the fully qualified path to the function in an SSRS expression:
=ReportHtmlHandler.HtmlTruncate.TruncateHtml(Fields!Comment.Value, 1000)
I could have added a calculated field to my dataset with this, but I was only using this value for one field, so I kept it at the field expression level.
All of this code gets called well before the HTML is processed or rendered by SSRS. I'm sure that any original IMG tag will be in the string.
This approach might work for you, possibly create a ExtractImg function which could be set as the source of an img on the report. I think some of the tricky bits for your requirement will be to handle multiple images as well as embedding the extracted img. But you might be able to do this simply with a external reference to an image. I haven't done much with external images in SSRS.
An MSDN blog entry on calling a custom dll from SSRS: http://support.microsoft.com/kb/920769