0

In an SSRS 2008 R2 report, the users are going to export the data to: csv (comma delimited) and excel.

I am using the following to display if a column is visible or not:

=IIF(Mid(Globals!RenderFormat.Name,1,5)="EXCEL" AND First(Len(Fields!CustomerNumber.Value)) > 0,False,true)

I have set the DataElementOutput=Output for the textbox that displays the value.

I have left DataElementOutput=Auto for the textbox that contains the column header.

When exporting to csv (comma delimited) or excel, I basically want the column to be visible when there is data in the field and the column not to be visible when there is no data.

The code works for excel but the code does not work for comma delimited.

Thus, can you tell me what I can do so the column is not disaplyed when the data is exported to csv (comma delimited)?

analyticalpicasso
  • 1,993
  • 8
  • 26
  • 45
user1816979
  • 511
  • 4
  • 13
  • 25

1 Answers1

0

You may attempt to do this with a continuation of statement accounting for the "CSV" output type.

=IIF( (Mid(Globals!RenderFormat.Name,1,5)="EXCEL" OR Mid(Globals!RenderFormat.Name,1,5)="CSV") AND First(Len(Fields!CustomerNumber.Value)) > 0,False,true)

Or a switch statement:

=Switch(Mid(Globals!RenderFormat.Name,1,5)="EXCEL" AND First(Len(Fields!CustomerNumber.Value)) > 0,False, Mid(Globals!RenderFormat.Name,1,5)="CSV" AND First(Len(Fields!CustomerNumber.Value)) > 0,False,true)

However....

The problem may be due to the nature of a csv file being a simpler format that cannot handle this in output. It depends on how SSRS handles the output if it is hard writing the output before the write operation. It may simply not work because of the limitations of the format of CSV. If this was the case you may be able to simple take the Excel output and save it to CSV either in code or a manual operation.

djangojazz
  • 14,131
  • 10
  • 56
  • 94
  • I tried your suggestion but that did not work. Thus can you tell me why this would just be a problem with csv? How is that a simpler format that can not handle the logic? Is this a problem with ssrs exporting to a csv file? – user1816979 Jan 03 '14 at 20:01
  • I don't know is the problem, I wish I did. I am just guessing that due to CSV being a simpler format of just comma seperated values it cannot handle more difficult presentation. I would assume you may have been able to get around this by hoping that SSRS creates AFTER aplying the expression, but it appears it will not. You may just stick with Excel or if it is a requirement to use CSV, manually convert an Excel file or do a conservion in code like C# or VB. – djangojazz Jan 03 '14 at 20:38
  • Well depending on how simple the layout is, you can just do simple rename and see if that works. Then get a C# piece of code to do just a 'move' or 'copy' off of a file operation to the same directory. If you want to get more verbose you could create some method to determine all the stuff in the file like this thread: http://stackoverflow.com/questions/2536181/is-there-any-simple-way-to-convert-xls-file-to-csv-file-excel. – djangojazz Jan 06 '14 at 17:13