sparhawk83
IS-IT--Management
Hi folks,
I am using a DTS package to first copy a template excel file, then populate it with pre-defined data from a view, then convert the numerical data back to being numerical using VBScript within the DTS package as I have not found a way to get SQL Server to output the data as a number, i.e. you can open the excel workbook and it will show as a number rather than text,
The problem i have is that the vbscript copies in '0' to convert, i'll paste in the code below this text, it leaves '0's in columns where there is no data, what i need to do is either have a way to remove those rows from the excel sheet using the vbscript, or to convert the numericals back only where there are populated rows, see below:
Function Main()
Dim xlApp
Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open("\\ServerName\Share\Folder\sheetname.xls")
Set WS = xlApp.Application.Workbooks(1).Sheets(1)
xlApp.Range("J1").Select
'enter 1 in an empty cell to use for conversion
xlApp.ActiveCell.FormulaR1C1 = "1"
xlApp.Range("J1").Select
xlApp.Selection.Copy
'copy the 1 for conversion
xlApp.Range("F2:F873").Select
xlApp.Selection.PasteSpecial -4104, 4, False, False
'delete the 1
xlApp.Range("J1").Delete
'Additional stuff I added for simple conversions (not text to number)
xlApp.Columns("H:H").Select
xlApp.Selection.NumberFormat = "0.00%"
'Save and close open workbook
xlApp.ActiveWorkbook.Save
xlApp.ActiveWorkbook.Close
Main = DTSTaskExecResult_Success
End Function
I've found some code in some websites, but they seem to be based on VBA within excel and macros rather than within the DTS package which is what I need,
Alternatively if there is a way of getting DTS to output the data into excel and leave any numerical data as numerical data that would get around the whole problem,
Many thanks for any assistance!
S
I am using a DTS package to first copy a template excel file, then populate it with pre-defined data from a view, then convert the numerical data back to being numerical using VBScript within the DTS package as I have not found a way to get SQL Server to output the data as a number, i.e. you can open the excel workbook and it will show as a number rather than text,
The problem i have is that the vbscript copies in '0' to convert, i'll paste in the code below this text, it leaves '0's in columns where there is no data, what i need to do is either have a way to remove those rows from the excel sheet using the vbscript, or to convert the numericals back only where there are populated rows, see below:
Function Main()
Dim xlApp
Set xlApp = CreateObject("Excel.Application")
Set xlWB = xlApp.Workbooks.Open("\\ServerName\Share\Folder\sheetname.xls")
Set WS = xlApp.Application.Workbooks(1).Sheets(1)
xlApp.Range("J1").Select
'enter 1 in an empty cell to use for conversion
xlApp.ActiveCell.FormulaR1C1 = "1"
xlApp.Range("J1").Select
xlApp.Selection.Copy
'copy the 1 for conversion
xlApp.Range("F2:F873").Select
xlApp.Selection.PasteSpecial -4104, 4, False, False
'delete the 1
xlApp.Range("J1").Delete
'Additional stuff I added for simple conversions (not text to number)
xlApp.Columns("H:H").Select
xlApp.Selection.NumberFormat = "0.00%"
'Save and close open workbook
xlApp.ActiveWorkbook.Save
xlApp.ActiveWorkbook.Close
Main = DTSTaskExecResult_Success
End Function
I've found some code in some websites, but they seem to be based on VBA within excel and macros rather than within the DTS package which is what I need,
Alternatively if there is a way of getting DTS to output the data into excel and leave any numerical data as numerical data that would get around the whole problem,
Many thanks for any assistance!
S