Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use SQL script to read the number and name of sheet in Excel

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to use SQL script to read the number and name of sheet in Excel". In daily operation, I believe many people have doubts about how to use SQL script to read the number and name of sheet in Excel. Xiaobian consulted all kinds of information and sorted out a simple and easy-to-use method of operation. I hope it will be helpful to answer the question of "how to use SQL script to read the number and name of sheet in Excel". Next, please follow the editor to study!

The copy code is as follows:

Get table (worksheet) or column (field) listings from an excel spreadsheet-- set the variable declare @ linkedServerName sysname = 'TempExcelSpreadsheet' declare @ excelFileUrl nvarchar (1000) =' D:\ text.xlsx'-- / SET-- delete the linked service (if it already exists) if exists (select null from sys.servers where name = @ linkedServerName) begin exec sp_dropserver @ server = @ linkedServerName @ droplogins = 'droplogins' end-- add service objects-- ACE 12.0 works well as * .xls and * .xlsx, you can also use Jet, but you can only access the * .xls file exec sp_addlinkedserver @ server = @ linkedServerName, @ srvproduct =' ACE 12.0, @ provider = 'Microsoft.ACE.OLEDB.12.0', @ datasrc = @ excelFileUrl, @ provstr =' Excel 12.0 HDR=Yes'-- get the current user declare @ suser_sname nvarchar = suser_sname ()-- add the current user as the login link service exec sp_addlinkedsrvlogin @ rmtsrvname = @ linkedServerName, @ useself = 'false', @ locallogin = @ suser_sname, @ rmtuser = null @ rmtpassword = null-- returns the column exec sp_tables_ex @ linkedServerName exec sp_columns_ex @ linkedServerName in sheet and each sheet-- deletes the linked service object if exists (select null from sys.servers where name = @ linkedServerName) begin exec sp_dropserver @ server = @ linkedServerName, @ droplogins = 'droplogins' end here The study on "how to use SQL script to read the number and name of sheet in Excel" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report