alter procedure _sp_ImportExcelFile
(@Source varchar(1000)
, @SourceSheet varchar (100)
, @DestinationTable varchar (100))
as
declare @retval int
EXEC master..xp_fileexist @Source, @retval output -- check if file exists
if @retval = 0
begin
print 'file does not exist.'
return
end
if @SourceSheet is null or @SourceSheet = ''
set @SourceSheet = '[projects_export$]'
else
set @SourceSheet = '[' + ltrim(rtrim(@SourceSheet)) + '$]'
if @DestinationTable is null or @DestinationTable = ''
set @DestinationTable = substring(@SourceSheet, 2, len(@SourceSheet) - 3) + convert(varchar, getdate(), 126)
exec('select * into [' + @DestinationTable + '] from openrowset
(''Microsoft.Jet.OLEDB.4.0'', ''Excel 8.0;HDR=YES;Database=' + @Source + ''', ' +
@SourceSheet + ')')
我正在使用它作为执行语句
exec _sp_ImportExcelFile 'D:\exceldata\','projects_export','ExcelData'
其中projects_export
是工作表的名称,ExcelData
是我的工作表的名称
但得到的错误为file doesn't exist