English 中文(简体)
• 如何使外壳电池自动化,同时复制来自舱服务器的数据
原标题:how to autosize excel cells while copying data from sql server

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)    

“entergraph

关于

T.Navin

Error while saving Macro Code:

“entergraph

问题回答

I guess you are transferring the data as csv (from your code). csv files can not be formatted.

之后,你可以在选择的平方位将焦夫案转换为Xx或xls。

从我迄今知道的情况来看(希望了解这方面的新情况,尽管如此),我这样做的唯一途径是预先准备前线文件和使用模板。

, ,

Option Explicit 

Sub AutoFitAllColumns() 

    Application.ScreenUpdating = False 

    Dim strWorksheetName As String 
    Dim objWorkBook As Worksheet 

    strWorksheetName = ActiveSheet.Name 

    For Each objWorkBook In ActiveWorkbook.Worksheets 
        On Error Resume Next 
        objWorkBook.Activate 
        Cells.EntireColumn.AutoFit 
    Next objWorkBook

    Sheets(strWorksheetName).Select 
    Application.ScreenUpdating = True 

End Sub 

Private Sub Workbook_Open()
    AutoFitAllColumns
End Sub

确保法典放在你作为模板使用的Excel档案中,然后首先提供该守则的副本。 页: 1 我不相信,如果你利用它打开使用Excel的.csv档案,会发生什么情况。 你们是否可以尝试?





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签