0

I am able to run a stored procedure and export it to csv using the following code:

function TestSQLStoredPrc()
{
$connString = "Data Source=xxxxxx,1433;Initial Catalog=TestDB;User Id=TestUser; Password=YYYYYYY;"
$Reference = Read-Host "Enter Name";
$QueryText = "exec dbo.GetUsersCountByName 'Test'"; 
$SqlConnection = new-object System.Data.SqlClient.SqlConnection;
$SqlConnection.ConnectionString = $connString;

$SqlCommand = $SqlConnection.CreateCommand();
$SqlCommand.CommandText = "EXEC dbo.GetUsersCountByName 'Test'";
$DataAdapter = new-object System.Data.SqlClient.SqlDataAdapter $SqlCommand
$dataset = new-object System.Data.Dataset 
Write-Host $DataAdapter.Fill($dataset) ' records have been exported.' 
$dataset.Tables[0] | Export-CSV C:\MyReport.csv -Force -NoTypeInformation
Write-Host 'New report C:\MyReport.csv has been successfully generated'
}

TestSQLStoredPrc

I am able to get a csv file as output. But I need to apply background color and formatting to the header column of the output csv file.

Can anyone help me to resolve this issue by providing some sample example.

Thanks & Regards, Santosh Kumar Patro

1
  • As per mjolinor's answer below you can't, the format does not support what you're asking of it. I would suggest you look at converting your CSV to XLS/XLSX format or another format which supports the desired formatting. Commented Oct 22, 2013 at 21:24

1 Answer 1

4

You can format it and save it as HTML, but you cannot do that and have it remain a .csv file. CSV is, by definition plaint text - there is no provision for storing foratting information in the file, only header names and values.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.