从SQL数据库填充数据时,Excel工作表中的列对齐出错

时间:2018-05-02 09:58:52

标签: sql-server excel

我想使用Excel工作表中的查询将数据从SQL数据库填充到Excel工作表。数据出现在excel中,但列以奇怪的方式对齐。我只是想让列出现在与select查询相同的对齐方式中。

选择查询:

select 
VVO.VV_CODE, 
V.Vessel_name, 
VVO.Arrival_date, 
isnull(IGM.VIR_NO,'NULL') as VIR_NO, 
isnull(VVO.TERMINAL_CODE,'NULL') as TERMINAL_CODE,
(SELECT
COUNT(BL_NO)
FROM
BL_DATA
WHERE
VV_CODE = VVO.VV_CODE AND
ISNULL(UNUSED_FLAG, '') <> '1') as TOTAL_INDEX,
(select CAST(COUNT(DISTINCT CONTAINER_NO) as int) from BL_Container  where (Container_Size_Code = 19 or Container_Size_Code = 1)  and BL_Container.VV_CODE = VVO.VV_CODE ) as TWENTY_FT,
(select CAST(COUNT(DISTINCT CONTAINER_NO) as int) from BL_Container  where (Container_Size_Code = 20 or Container_Size_Code = 2) and BL_Container.VV_CODE = VVO.VV_CODE ) as FOURTY_FT,
(select CAST(COUNT(DISTINCT CONTAINER_NO) as int) from BL_Container  where (Container_Size_Code = 3) and BL_Container.VV_CODE = VVO.VV_CODE ) as FOURTYFIVE_FT,
(select CAST(COUNT(DISTINCT CONTAINER_NO) as int) from BL_Container  where (Container_Size_Code = 20 or Container_Size_Code = 19 or Container_Size_Code = 1 or Container_Size_Code = 2 or Container_Size_Code = 3) and BL_Container.VV_CODE = VVO.VV_CODE ) as Total_No_of_Cntrs,
(select((select CAST(COUNT(DISTINCT CONTAINER_NO) as float) from BL_Container  where (Container_Size_Code = 19 or Container_Size_Code = 1) and BL_Container.VV_CODE = VVO.VV_CODE )/2 + (select CAST(COUNT(DISTINCT CONTAINER_NO) as float) from BL_Container  where (Container_Size_Code = 20 or Container_Size_Code = 2) and BL_Container.VV_CODE = VVO.VV_CODE ) + (select CAST(COUNT(DISTINCT CONTAINER_NO) as float) from BL_Container  where (Container_Size_Code = 3) and BL_Container.VV_CODE = VVO.VV_CODE ))) as Total_FFE
from Vessel_voyage VVO, Vessel V, IGM where V.Vessel_code = substring(VVO.VV_CODE,1,3) and VVO.VV_CODE = IGM.VV_CODE 

excel表中填充的结果数据如下,

Resultant Excel

1 个答案:

答案 0 :(得分:0)

分辨率 -

  1. 右键单击EXCEL列标题

  2. 转到 =&gt; 外部数据属性

  3. enter image description here

    1. 取消选中“保留列排序/过滤器/布局

    2. 刷新 Excel

    3. 结果Excel如下所示,

      enter image description here