June 20, 2006 at 3:26 pm
has anyone gotten past the obstacle of not being able to drop and recreate the table (worksheet) in an excel spreadsheet successfully?
June 21, 2006 at 5:52 am
We just use a sql task to drop table [table_name] and then another sql task to create table [table_name]
DROP TABLE NEW_TABLE
CREATE TABLE `New_Table` (
`pmt_no` Long ,
`amount` Double ,
`issue_dt` VarChar (12) ,
`pmt_vendor_name` VarChar (40) )
No Problems here.
June 21, 2006 at 9:39 am
I don't know if this is what you're asking (table being a multi-purpose word), but if the problem is recreating the spreadsheet file each time, I did this, which I got from somewhere on this site, plus the DTS site http://www.sqldts.com/
ActiveX Tasks
Delete the Spreadsheet
Option ExplicitFunction Main() Dim oFSODim sSourceFile
Set oFSO = CreateObject("Scripting.FileSystemObject") sSourceFile = DTSGlobalVariables("OutputFile").Value ' Check if file exists to prevent errorIf oFSO.FileExists(sSourceFile) Then
oFSO.DeleteFile sSourceFile
End If
' Clean UpSet oFSO = Nothing
Main = DTSTaskExecResult_SuccessEnd Function
Copy Empty File to DestinationOption ExplicitFunction Main() Dim oFSO
Dim sSourceFile
Dim sDestinationFile
Set oFSO = CreateObject("Scripting.FileSystemObject") sSourceFile = DTSGlobalVariables("SourceFile").ValuesDestinationFile = DTSGlobalVariables("OutputFile").Value
oFSO.CopyFile sSourceFile, sDestinationFile ' Clean UpSet oFSO = Nothing
Main = DTSTaskExecResult_SuccessEnd FunctionThis requires an empty file to copy in.
I set the file names up as global variables.
Mattie
June 21, 2006 at 10:25 am
the drop table recreate table statements succeed and the data is no longer there, however for some reason the file size does not shrink, and eventually I get an error saying that I exceeded the max number of rows.
I got around this by, deleting the file and copying a initial copy of the file into its place each time I have to run my dts package.
June 21, 2006 at 12:04 pm
We have quite a few DTS pacakages that function similarly. In each, we delete the spreadsheet using xp_cmdshell within an execute SQL task, and recreate it using the Visual Basic ActiveX Script task in DTS. Then we populate the spreadsheet, etc... Generally speaking, the process works very well.
June 21, 2006 at 12:39 pm
Can you post an example of your active x script to recreate the spreadsheet?
Thanks,
David
June 21, 2006 at 1:16 pm
Here goes... THe names have been changed to protect the guilty
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
Dim appExcel
Dim newBook
Dim xSheet5
Dim xSheet6
Dim oPackage
Dim oConn
Set appExcel = CreateObject("Excel.Application")
Set newBook = appExcel.Workbooks.Add
Set oSheet = newBook.Worksheets(1)
newBook.Sheets.Add
newBook.Sheets(1).Name = "Productivity YTD"
newBook.Sheets(2).Name = "EQ Weekly"
newBook.Sheets(3).Name = "EQ QTR"
newBook.Sheets(4).Name = "EQ YTD"
Set xSheet5 = newBook.Worksheets.add
xSheet5.Name = "Productivity QTR"
Set xSheet6 = newBook.Worksheets.add
xSheet6.Name = "Productivity Weekly"
Set oSheet=newBook.Sheets(1)
'oSheet.Range ("A1").Value = "Western Southern Productivity Rating Report"
Title (oSheet)
Set oSheet=newBook.Sheets(2)
'oSheet.Range ("A1").Value = "Western Southern Productivity Rating Report 2"
Title (oSheet)
Set oSheet=newBook.Sheets(3)
'oSheet.Range ("A1").Value = "Western Southern Qualifier Rating Report"
Title (oSheet)
Set oSheet=newBook.Sheets(4)
'oSheet.Range ("A1").Value = "Western Southern Qualifier Rating Report 2"
Title (oSheet)
Set oSheet=newBook.Sheets(5)
'oSheet.Range ("A1").Value = "Western Southern Productivity Rating Report 3"
Title (oSheet)
Set oSheet=newBook.Sheets(6)
'oSheet.Range ("A1").Value = "Western Southern Qualifier Rating Report 3"
Title (oSheet)
' Specify the name of the new ExcelFile to be created
DTSGlobalVariables("FileName").Value = "\\server\...\WestSouthWeekly.xls"
With newBook
.SaveAs DTSGlobalVariables("FileName").Value
.save
End With
appExcel.quit
'Destroy all objects
set appExcel = nothing
set newBook = nothing
set oSheet = nothing
Main = DTSTaskExecResult_Success
End Function
Sub Title(oSheet)
oSheet.Range("A1").Value = "Division Code"
oSheet.Range("B1").Value = "District"
oSheet.Range("C1").Value = "Name"
oSheet.Range("D1").Value = "Do Not Proceed"
oSheet.Range("E1").Value = "Proceed"
oSheet.Range("F1").Value = "Total"
oSheet.Range("G1").Value = "% Passed"
oSheet.Range("H1").Value = "SDate"
oSheet.Range("I1").Value = "EDate"
End Sub
June 22, 2006 at 12:57 pm
As far as the Drop Table, Create Table SQL Tasks, You have to make sure that the Insert/Names in Excel is reading your table correctly. Then you can not do anything to the table after creation by SQL. If you change or manipulate any of the data in the excel sheet ON THAT SHEET, it will not recreate properly. To manipulate the data, you'll have to link to it from another sheet and do your calculations, formatting, manipulations on that sheet.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply