Thursday, March 29, 2012

Exporting Report Builder Tabular Report to CSV

A simple tabular Report Builder report was written to feed another system that requires quoted CSV. I have two issues when exported:

1) I can't get control over the exported column names. Currently, they are exported as "FIELDNAME_Value".

When I try to change the column headings in the designer, it has no effect on the exported column names

When I create a New Field and specify my desired column name (e.g., COMPANY), the export appears as COMPANY_Value.

How do I control these names for the CSV export?

2) The spec calls for quoted text. In my export, only values with special characters are quoted.

Thanks in advance.

-DRB

1) The CSV renderer gets the column names from each TextBox's DataElementName property. This property is exposed though Report Designer in VS.NET, but not through Report Builder. If you want to control the CSV columns you'll need to open the report in Report Designer, set DataElementName, and then redeploy back to the server.

2) The CSV renderer only qualifies values when they values contain the field or record delimiter. There isn't a way to force quotes around every text value.

I hope this helps.

-Chris

|||

Chris:

Thank you for the lead on the CSV column header name. It didn't quite work. Here's what I did:

1) From Report Builder, Save to File.

2) Move RDL to server.

3) On server, launch Visual Studio and open a new Report Services project.

4) Add the RDL to the project. Set the DataElementName property on every element.

5) Choose File > Save [filename] As to save updated RDL.

6) Move updated RDL back to local client and Load from File in Report Builder.

7) Run and export the report.

In my experience, the exported column heading did not change. Here's a snippet from the RDL and from the CSV:

<TableCell>
<ReportItems>
<Textbox Name="SITEADDRESS_Value">
<DataElementOutput>Output</DataElementOutput>
<ZIndex>5</ZIndex>
<Style>
<BorderStyle>
<Default>Solid</Default>
</BorderStyle>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<FontFamily>Tahoma</FontFamily>
<FontSize>8pt</FontSize>
<BorderColor>
<Default>LightGrey</Default>
</BorderColor>
<BackgroundColor>White</BackgroundColor>
<PaddingRight>2pt</PaddingRight>
<PaddingTop>2pt</PaddingTop>
<Language>en-US</Language>
</Style>
<CanGrow>true</CanGrow>
<DataElementName>BUSINESS STREET</DataElementName>
<Value>=Fields!BUSINESSSTREET.Value</Value>
</Textbox>
</ReportItems>

From the CSV header row:
FACILITYNAME_Value,SITEADDRESS_Value,CityNameSiteAddressCITYNAME_Value,STATE_Value,ZIP_Value,FAX_Value,PHONE_Value

As you can see, the column heading still took its name from the Name property (best I can tell).

Please advise.

-D. B.

|||

Report Builder would open report from server, not from disk. In Visual Studio, you are saving report to disk, not deploying it to the server. Try deploying it to the report server from VS.NET and checking if this your header comes out as you expected in CSV, and then opening it in Report Builder.

CSV renderer always takes the name for the column from <DataElementName>, if present.

|||

Thank you Dennis:

I may have a new related related challenge. When I attempt to publish and run the report from within VS as directed, I receive the following error:

An error occurred during local report processing. The definition of the report /{report name} is invalid. The DataElementName property for the Textbox SITEADDRESS_Value contains "BUSINESS STREET", which is not a CLS-compliant identifier.

I appreciate that the space is the source of the error... but (back to my original post), my customer requires a CSV file with column headers such as "BUSINESS STREET".

Any other ideas?

-D.R.B.

|||

Unfortunately, DataElementName has to be CLS-Complaint, so you can't have spaces in the column name. Best available alternative is "_" character ("BUSINESS_STREET").

No comments:

Post a Comment