SQL 输出到 Excel 错误

SQL output to Excel Errors

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

这是数据的样子:

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

但是因为马车 returns 这就是我得到的

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 我在它之前和之后有一堆需要排队的专栏。

在您的 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。这看起来会一团糟,直到您确保在“格式单元格”下选中了 'Wrap Text',然后回车 returns 将出现在单元格中。