May 8, 2007 at 3:28 am
May 8, 2007 at 5:11 pm
I don't remember where I got these from... they seem to work... of course, the spreadsheet must already exist but you can make a master template, copy it to a new file, and update the new file.
INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 5.0;Database=C:\Temp\NorthwindTest.xls;',
'SELECT EmployeeID,LastName,FirstName FROM [Sheet1$]')
SELECT EmployeeID,LastName,FirstName FROM Northwind.dbo.Employees
INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 5.0;Database=C:\Temp\NorthwindTest.xls;',
'SELECT EmployeeID,LastName,FirstName FROM [Sheet1$] WHERE EmployeeID = ''''')
SELECT EmployeeID,LastName,FirstName FROM Northwind.dbo.Employees
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Temp\NorthwindTest.xls;HDR=YES',
'SELECT * FROM [Sheet1$]')
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Temp\NorthwindTest.xls;HDR=no',
'SELECT * FROM [Sheet1$a5:a9]')
UPDATE OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 5.0;Database=C:\Temp\NorthwindTest.xls;',
'SELECT EmployeeID,LastName,FirstName FROM [Sheet1$]')
SET LastName = NULL
WHERE EmployeeID = 5
UPDATE OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 5.0;Database=C:\Temp\NorthwindTest.xls;',
'SELECT EmployeeID,LastName,FirstName FROM [Sheet1$]')
SET EmployeeID = '',
LastName = '',
FirstName = ''
WHERE EmployeeID IS NOT NULL
DELETE OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Temp\NorthwindTest.xls;HDR=Yes',
'SELECT EmployeeID FROM [Sheet1$]')
WHERE EmployeeID = 5
SELECT * FROM OPENROWSET('MSDASQL',
'Driver={Microsoft Excel Driver (*.xls)};DBQ=C:\Temp\NorthwindTest.xls',
'SELECT * FROM [Sheet1$]')
DELETE OPENROWSET('MSDASQL',
'Driver={Microsoft Excel Driver (*.xls)};DBQ=C:\Temp\NorthwindTest.xls',
'SELECT * FROM [Sheet1$]')
--Jeff Moden
Change is inevitable... Change for the better is not.
May 8, 2007 at 6:10 pm
Problem with this you MUST know the name of the sheet inside of Excel Workbook.
And users use to rename/delete those sheets without asking permissions from those bloody developers.
_____________
Code for TallyGenerator
May 8, 2007 at 7:56 pm
It looks like a perfect solution for me. Thanks heaps.
May 8, 2007 at 8:02 pm
No problem at all. I will create a blank workbook having N worksheets with headers. I will name the worksheets sequentially: Sheet1, Sheet2, ... , SheetN (This can be automated, I just created a workbook with over 1500 worksheets. Excel 2003 help tells that the number of worksheets is "Limited by available memory"!). Those worksheets can be renamed to the category name later, when user opens the workbook with "AutoOpen" procedure.
After the report is finished I will copy the result into user accessible directory and replace the one on the server with blank file again.
May 8, 2007 at 9:27 pm
> I just created a workbook with over 1500 worksheets.
Good revenge!
_____________
Code for TallyGenerator
Viewing 6 posts - 16 through 20 (of 20 total)
You must be logged in to reply to this topic. Login to reply