Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
anmolmalviya05
Super User
Super User

SSRS Report in txt format

I have created a ssrs report and end user wants the result in txt format.
I tried to export the report in csv and then convert it into txt tab delimited format.
But due to this the data and column name are getting misplaced.
Is there any way so that the data will remain aligned to Column name.

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @anmolmalviya05 

 

Thanks for the reply from lbendlin, please allow me to provide another insight:

 

You can use PowerShell to convert the csv file to txt file. The test is as follows for your reference:

 

This is the cvs file I exported in SSRS.

vxuxinyimsft_0-1728295168352.png

 

code in PowerShell:

# Define CSV file path
$csvFilePath = "Disk:\path\to\your\file.csv"
# Define output TXT file path
$txtFilePath = "Disk:\path\to\your\file.txt"

# Read CSV file
$csvData = Import-Csv -Path $csvFilePath -Delimiter ','

# Get the maximum length of each column
$maxLengths =$csvData[0].PSObject.Properties.Name.ForEach({
    $maxLength =$_.Length
    foreach ($row in $csvData) {
        $length =$row.$_.ToString().Length
        if ($length -gt $maxLength) {
            $maxLength =$length
        }
    }
    $maxLength
})

# Convert column names to a string with tab delimiters
$columnNames =$csvData[0].PSObject.Properties.Name.ForEach({
    $_.PadRight($maxLengths[$csvData[0].PSObject.Properties.Name.IndexOf($_)])
}) -join "`t"

# Convert CSV data to strings with tab delimiters, ensuring alignment
$txtData =$csvData.ForEach({
    $_.PSObject.Properties.ForEach({
        $_.Value.ToString().PadRight($maxLengths[$csvData[0].PSObject.Properties.Name.IndexOf($_.Name)])
    }) -join "`t"
})

# Combine column names and CSV data
$txtContent =$columnNames + "`r`n" + ($txtData -join "`r`n")

# Write content to TXT file
$txtContent | Out-File -FilePath $txtFilePath -Encoding ASCII

 

Output:

vxuxinyimsft_1-1728295425155.png

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @lbendlin, @Anonymous Thanks for your response.

The powershell script worked.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @anmolmalviya05 

 

Thanks for the reply from lbendlin, please allow me to provide another insight:

 

You can use PowerShell to convert the csv file to txt file. The test is as follows for your reference:

 

This is the cvs file I exported in SSRS.

vxuxinyimsft_0-1728295168352.png

 

code in PowerShell:

# Define CSV file path
$csvFilePath = "Disk:\path\to\your\file.csv"
# Define output TXT file path
$txtFilePath = "Disk:\path\to\your\file.txt"

# Read CSV file
$csvData = Import-Csv -Path $csvFilePath -Delimiter ','

# Get the maximum length of each column
$maxLengths =$csvData[0].PSObject.Properties.Name.ForEach({
    $maxLength =$_.Length
    foreach ($row in $csvData) {
        $length =$row.$_.ToString().Length
        if ($length -gt $maxLength) {
            $maxLength =$length
        }
    }
    $maxLength
})

# Convert column names to a string with tab delimiters
$columnNames =$csvData[0].PSObject.Properties.Name.ForEach({
    $_.PadRight($maxLengths[$csvData[0].PSObject.Properties.Name.IndexOf($_)])
}) -join "`t"

# Convert CSV data to strings with tab delimiters, ensuring alignment
$txtData =$csvData.ForEach({
    $_.PSObject.Properties.ForEach({
        $_.Value.ToString().PadRight($maxLengths[$csvData[0].PSObject.Properties.Name.IndexOf($_.Name)])
    }) -join "`t"
})

# Combine column names and CSV data
$txtContent =$columnNames + "`r`n" + ($txtData -join "`r`n")

# Write content to TXT file
$txtContent | Out-File -FilePath $txtFilePath -Encoding ASCII

 

Output:

vxuxinyimsft_1-1728295425155.png

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @lbendlin, @Anonymous Thanks for your response.

The powershell script worked.

lbendlin
Super User
Super User

The whole point of a SSRS report (paginated report) is the page formatting with headers and footers etc.  It will be very hard if not impossible to convert that back into plain CSV.   Can't you export the CSV from the data source directly?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.