简体   繁体   English

如何将SQL数据导出到excel

[英]How to export SQL data in to excel

I am using SQLCMD command to run a script and i need to output the result in to an excel file in XLSX format.我正在使用 SQLCMD 命令运行脚本,我需要将结果输出到 XLSX 格式的 excel 文件中。 How do i do that ?我怎么做 ?

Thanks in advance.提前致谢。

I recommend you use the bcp utility to do that.我建议您使用 bcp 实用程序来执行此操作。 The bcp utility works vary fast for situation like yours and it is very flexible. bcp 实用程序在像您这样的情况下工作得很快,而且非常灵活。 You can use it to output the contents of a table or query to a "comma separated file" using any column separator you want and then consume that file in Excel.您可以使用它使用所需的任何列分隔符将表或查询的内容输出到“逗号分隔文件”,然后在 Excel 中使用该文件。

A also believe that you could name the file with the XLSX extension, but haven't tested that. A 还相信您可以使用 XLSX 扩展名命名文件,但尚未对此进行测试。

Here is the link to the utility's documentation.是实用程序文档的链接。

If your script is more complex, I recommend you create a stored procedure for it's logic.如果您的脚本更复杂,我建议您为其逻辑创建一个存储过程。 You could drop this procedure once you're done with it.完成后,您可以放弃此过程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM