Reputation: 404
I need to write data to a new Excel sheet in an existing Excel file, with T-SQL.
I need to use ACE OLEDB and OPENROWSET
statement.
Usually, I write from a table to an existing Excel sheet, with:
INSERT INTO OPENROWSET (
'Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=c:\myExcelFile.xlsx;'
'SELECT Col_A, Col_B, Col_C FROM [SheetName$]')
SELECT Col_A, Col_B, Col_C
FROM dbo.MyTable
The code above works only for an existing sheet, which has 3 columns, and the names Col_A, Col_B, Col_C in the first row.
I've tried to modify the OPENROWSET
statement using a [SheetName$]
that don't exists. I've tried with or without $
characters, with column names or with *
wildcard, but nothing worked.
Thanks
Upvotes: 0
Views: 222