代码之家  ›  专栏  ›  技术社区  ›  Elizabeth

SQL输出到Excel错误

  •  0
  • Elizabeth  · 技术社区  · 8 年前

    如何将SQL查询中的数百行输出复制到excel中的各行中。为了澄清我的数百行中的每一行都有多个换行符,但我在选择时没有看到这些换行符。

    数据如下所示:

    Description column in the table:
    
    Hello world this is sample text
    another line of text for example
    and a third line example
    

    但是数据是这样的

    Hello world <new line break> this is sample <new line break> text
    another line of <new line break>  text for example
    and a third <new line break> line example
    

    当我试图将其复制到excel中时,我希望它进入H列(在我的情况下),每一行都应该在自己的行中。

    row 1:     Hello world <new line break> this is sample <new line break> text
    row 2:     another line of <new line break>  text for example
    row 3:     and a third <new line break> line example
    

    但由于马车返回,这就是我得到的

    row 1:     Hello world
    row 2:     this is sample 
    row 3:     text
    row 4:     another line of
    row 5:     text for example
    row 6:     and a third
    row 7:     line example
    

    如果这是一个单列,我会这样做,但正如我提到的,这是H列,我在它之前和之后有很多列需要排列。

    1 回复  |  直到 8 年前
        1
  •  0
  •   tysonwright    8 年前

    在SQL查询中,不要将字段中的换行符替换为空格,而是将其替换为:

       " & CHAR(10) & "
    

    让该列以等号和双引号开始,以双引号结束。因此,测试数据将输出为

    ="Hello world" & CHAR(10) & "this is sample " & CHAR(10) & " text"
    ="another line of " & CHAR(10) & "  text for example"
    ="and a third " & CHAR(10) & " line example"
    

    将其放入Excel。这看起来会很混乱,直到您确保在“格式单元格”下选中“换行文本”,然后回车符将出现在单元格中。

    推荐文章