i am exporting sql data into excel using stored procedure.. while opening the excel few cell values are partially hidden, i want to resize it including the header.. and want to make the header bolder.. plz help me out to solve this issue..
sql stored procedure:
alter procedure usp_example
(
@db_name varchar(100),
@schm_name varchar(100),
@table_name varchar(100),
@file_name varchar(100)
)
as
--Generate column names as a recordset
declare @columns varchar(8000), @sql varchar(8000) ,
@sql1 varchar(8000), @data_file varchar(100)
select
@columns=coalesce(@columns+ , , )+column_name+ as +column_name
from
information_schema.columns
where
table_name=@table_name
select @columns= +replace(replace(@columns, as , as ), , , , )
--Create a dummy file to have actual data
select @data_file=substring(@file_name,1,len(@file_name)-
charindex( ,reverse(@file_name)))+ data_file.csv
--Generate column names in the passed EXCEL file
set @sql= bcp " select DATE , *, SHIFT , SETUPTIME from (select +@columns+ ) as t" queryout c:Daily_Reportsdaily_machinedescription_report_summary.csv -c -t, -T -S + @@servername
exec master..xp_cmdshell @sql
print @sql
--Generate data in the dummy file
set @sql= bcp "SELECT convert(varchar, ENTRY_DATE, 105) as DATE ,machinename as Machine,RunTime,ECTime,ReworkTime as RWTime,IdleTime,DownTime,SHIFT_TYPE as Shift,SetupTime FROM VentureBI_Prod_Test..view_admin_report ORDER BY segment " queryout c:Daily_Reportsdata_file.csv -c -t, -T -S + @@servername
exec master..xp_cmdshell @sql
--Copy dummy file to passed EXCEL file
set @sql= exec master..xp_cmdshell type +@data_file+ >> " +@file_name+ "
exec(@sql)
----Delete dummy file
set @sql= exec master..xp_cmdshell del +@data_file+
exec(@sql)
关于
T.Navin