Hi all,
We have a recurring need to export data from SQL Server tables to Excel.
We made a little script that does everything alright, except that it exports to the TXT format instead of exporting to Excel itself.
The relevant part of the code is:
EXEC master..xp_cmdshell ‘bcp “select * from database..tablename” queryout ‘+ @FileName +’ -c -Uusername -Ppassword’
I think bcp only exports to TXT/CSV, but I wish I could export to Excel. The Excel files are to be created while the export process takes place, i.e., we don’t want to create the Excel files in advanced so SQL Server can export to them. I’d also like to know whether one can export to different several worksheets within the same Excel file, but we can discuss that later.
I think this can be done, since when exporting manually via DTSs SQL Server DOES export to Excel, even to several worksheets.
Any ideas?