Hi,
I am using Activex scripts in SQL Server DTS Packages to
read from a .csv file and write it to a Excel file. The
actual problem is the leading zeroes are being truncated
in the XL file.
Hence, I use ActiveSheet.QueryTables.Add method to define
the formating properties that I require. It creates the
Excel file successfully but it neither transfers the data
nor does it format the cells. Below is my code. Pls.
let me know if I am going with the right approach. VERY
URGENT.
If any of you can suggest me an alternate way on how I
can transfer the data from .csv to .xls without loosing
the leading zeroes, I would be really grateful.
with regards,
Ram
Function Main()
Dim Xcl
Dim strDestinationFileName
Dim strSourceFileName
'strDestinationFileName
= "D:\_Clients_Data\Monument\Order\vipul2.xls"
strSourceFileName = DTSGlobalVariables
("Data_File_Path")&DTSGlobalVariables("Data_File_Name")
strDestinationFileName = DTSGlobalVariables
("Schema_File_Path")&DTSGlobalVariables
("Schema_File_Name")
Set Xcl = CreateObject("Excel.Application")
Xcl.Visible = true
Set newBook = Xcl.Workbooks.Add
newBook.Worksheets(1).Name="My First WorkSheet"
newBook.Worksheets(2).delete
newBook.Worksheets(2).delete
newbook.Worksheets(1).Activate
'importing the .csv file
With ActiveSheet.QueryTables.Add
(Connection:= "TEXT; D:\_Clients_Data\Monument\Order\09-
03_Order_Monument.csv", Destination:= Range ("A1") )
.Name = strDestinationFileName
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier =
xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1)
.Refresh BackgroundQuery:= False
End With
newBook.SaveAs strDestinationFileName
Xcl.Visible = false
Set Xcl = nothing
Main = DTSTaskExecResult_Success
End Function