--From the Excel file, import data into the SQL database, very simple, directly with the following statement:/*===================================================================*/- -If the table that accepts data import already exists insert into table select * from OPENROWSET (' MICROSOFT. JET. oledb.4.0 ', ' Excel 5.0; Hdr=yes;database=c:\test.xls ', sheet1$)--If you import data and generate a table select * into table from OPENROWSET (' MICROSOFT. JET. oledb.4.0 ', ' Excel 5.0; Hdr=yes;database=c:\test.xls ', sheet1$)/*===================================================================*/- -If you export data from a SQL database to Excel, if the Excel file already exists and you have created a header for the data you want to receive, you can simply use: INSERT INTO OPENROWSET (' MICROSOFT. JET. oledb.4.0 ', ' Excel 5.0; Hdr=yes;database=c:\test.xls ', sheet1$) SELECT * FROM table-if the Excel file does not exist, you can also use BCP to lead to a file of the class Excel, note the case:--export the table to exec master. xp_cmdshell ' bcp database name. dbo. Table name out "C:\Test.xls"///-/s "server name"/"User name"-P "password"--the case of the export query exec master. xp_cmdshell ' bcp ' select au_fname, au_lname from pubs. Authors ORDER BY au_lname "Queryout" C:\Test.xls "/C-/s" server name "/u" user name "-P" password "'/*--Description: C:\Test.xls is an imported/exported Excel file name. sheet1$ The worksheet name for the Excel file, which is typically added in order to be used normally.--*/