Forum Discussion

callenbkd's avatar
callenbkd
Helper II
5 months ago
Solved

Exporting SSRS Report to Text

Greetings. 

 

I've created this report in the image. I'd like to export it to a text file that looks like what it is. 

 

Here's part of the output. 

I added a custom render to the rsreportserver.config file. However, when I export it, the header appears on the same row as the row below it instead of on a top row. 

Do I need to change the report to put everything into one text field using unions? Everything is concatenated together on each row so it's one field per row. 

 

For example, in a single text box

"010"&"FISHFRY4383 "&"AP0"&SPACE(16)&format(today(),"yyyyMMdd")&FORMAT(now(), "HHmm")&SPACE(10)&SPACE(291) as record

UNION ALL

Fields!PaymentType.Value="Check","060"&"CHK"&"X"&LEFT(RTRIM(Fields!VENDORID.Value)&SPACE(10),10)&"UM"&SPACE(2)&"USD"&LEFT(RTRIM(Fields!DOCNUMBR.Value)&SPACE(10),10)&FORMAT(Fields!DOCDATE.Value,"yyyyMMdd")&Right(CStr(IIf(IsNothing(Fields!DOCAMNT.Value), 0, Fix(Abs(Fields!DOCAMNT.Value)))), 13) & LEFT(RTRIM(Fields!VENDNAME.Value) & SPACE(35),35)&SPACE(35)&LEFT(RTRIM(Fields!ADDRESS1.Value)&SPACE(35),35)&LEFT(RTRIM(Fields!ADDRESS2.Value)&SPACE(35),35)&LEFT(RTRIM(Fields!ADDRESS3.Value)&SPACE(35),35)&LEFT(RTRIM(Fields!CITY.Value)&SPACE(27),27)&LEFT(RTRIM(Fields!STATE.Value)&SPACE(2),2)&LEFT(LEFT(Fields!ZIPCODE.Value,5)&SPACE(9),9)&" "&"US "&RIGHT("00000"&CStr(Fields!ApplyRecordsCount.Value),5)&SPACE(10)&SPACE(50)&SPACE(13) as record

UNION ALL

"090"&
Right(CStr(IIf(IsNothing(Fields!CheckTotal.Value), 0, Fix(Abs(0)))), 13)&
RIGHT("0000000"&CStr(Fields!CheckCount.Value),7)&
Right(CStr(IIf(IsNothing(Fields!ACHTotal.Value), 0, Fix(Abs(0)))), 13)&
RIGHT("0000000"&CStr(Fields!ACHCount.Value),7)&
"0000000000000"&"0000000"&
Right(CStr(IIf(IsNothing(Fields!CardTotal.Value), 0, Fix(Abs(0)))), 13)&
RIGHT("0000000"&CStr(Fields!CardCount.Value),7)&Right(CStr(IIf(IsNothing(Fields!TotalPaymentAmount.Value), 0, Fix(Abs(0)))), 13)&
RIGHT("0000000"&CStr(Fields!TotalPaymentCount.Value),7)&Right(CStr(IIf(IsNothing(Fields!TotalPaymentAmount.Value), 0, Fix(Abs(0)))), 13)&
RIGHT("0000000"&CStr(Fields!TotalPaymentCount.Value),7)&SPACE(227) as record

 

I cut off what I did in another report, but above is essentially what I did for another client. If there's no way to export the above report as designed, I'll change it to match this bottom structure. 

 

Thank you

 

 

 

 

  • Hi callenbkd ,

    Thank you for sharing the details.

    The behavior you are seeing is expected when exporting SSRS reports to Text/CSV format. The Text renderer does not preserve the visual layout of the report. Instead, it exports data based on the tablix row and column structure, which can cause header elements and detail rows to appear on the same line if they belong to the same data region.
    For scenarios where a specific fixed-width text format is required, the recommended approach is to generate the output as one concatenated field per row, for example, a Record column created using expressions or SQL logic. The report can then use a single column tablix bound to that field so that each dataset row corresponds to exactly one line in the exported text file.
    Based on the example you provided, restructuring the report to follow this pattern similar to your UNION/concatenated record example would be the most reliable way to ensure the exported file matches the expected text format.

    Best Regards,
    Chaithra.

2 Replies

  • v-echaithra's avatar
    v-echaithra
    Community Support

    Hi callenbkd ,

    Thank you for sharing the details.

    The behavior you are seeing is expected when exporting SSRS reports to Text/CSV format. The Text renderer does not preserve the visual layout of the report. Instead, it exports data based on the tablix row and column structure, which can cause header elements and detail rows to appear on the same line if they belong to the same data region.
    For scenarios where a specific fixed-width text format is required, the recommended approach is to generate the output as one concatenated field per row, for example, a Record column created using expressions or SQL logic. The report can then use a single column tablix bound to that field so that each dataset row corresponds to exactly one line in the exported text file.
    Based on the example you provided, restructuring the report to follow this pattern similar to your UNION/concatenated record example would be the most reliable way to ensure the exported file matches the expected text format.

    Best Regards,
    Chaithra.