views:

204

answers:

1

I have a stored procedure that manipulates some data in an excel spreadsheet. I am importing data by creating a QueryTable object. I would like to set TextFileColumnDataTypes property for the object but I can't figure out how to pass in an array to the sp_OASetProperty routine.

This is what my code looks like but obviously it doesn't work:

EXECUTE @rc = master..sp_OASetProperty @xlQueryTable, 'TextFileColumnDataTypes', 'Array(xlTextFormat, xlTextFormat, xlGeneralFormat)'

Is there any way to do this?

A: 

Where do the values for xlTextFormat and xlGeneralFormat come from? Is it possible this should be one of the following:

DECLARE @command VARCHAR(255);

SET @command = 'Array(' + @xlTextFormat + ', ' + @xlTextFormat + ', ' + @xlGeneralFormat + ')';
-- or
SET @command = 'Array("' + @xlTextFormat + '", "' + @xlTextFormat + '", "' + @xlGeneralFormat + '")';
-- or
SET @command = 'Array("xlTextFormat", "xlTextFormat", "xlGeneralFormat")';

EXEC @rc = master..sp_OASetProperty @xlQueryTable, 'TextFileColumnDataTypes', @command;

Otherwise maybe you should ditch sp_OA and use CLR.

Aaron Bertrand
Thanks for the response. The values xlTextFormat and xlGeneralFormat are excel constants which I pulled from [msdn](http://msdn.microsoft.com/en-us/library/aa215749%28office.11%29.aspx)Rewriting the procedure using CLR is possible but that would be a last resort option.
Gsur
Okay sorry, I don't have any other suggestions. I stopped using sp_OA when 2005 was released, and I've never used it to automate Excel.
Aaron Bertrand