Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-08-08 : 09:01:59
|
| justin writes "I am completing a data extract and need to format text in the result set. I need to format text to be right justified with leading blanks, also return values with leading zeros. This result set is too large to complete and make the edits in excel, and it also needs to be automated. Therefore the best solution is to include the edits in my query to pull the data. Please advise. Thanks in advance,Justin WilsonConsultantUrban Sciencejjwilson@urbanscience.com" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-08-08 : 09:08:25
|
| If you're using DTS to export the data, then it's better to write an ActiveX task to open the Excel sheet and change the cell formats accordingly. Left-padding with spaces is at best an unreliable way to right-align data in an Excel sheet.The following snippet can be pasted into an ActiveX task in your DTS package:Function Main()Dim sht, excelSet excel=CreateObject("Excel.Application")excel.Workbooks.Open("C:\test.xls") 'change the file name to match yoursSet sheet = excel.ActiveWorkbook.ActiveSheetsheet.Range("D:D").NumberFormat = "000000" formats column D with leading zero formatsheet.Range("F:F").HorizontalAlignment = -4152 'formats column F as right-alignedexcel.ActiveWorkbook.Saveexcel.ActiveWorkbook.CloseSet excel=NothingMain = DTSTaskExecResult_SuccessEnd FunctionAdd this task, and then create an On Success taskflow from the Excel step to this one. After the transfer is complete, this code will run and will format the Excel sheet automatically. Simply change the column designations as appropriate.I tested this using the sales table from the pubs database, if you want to throw together an example to see how it works.Edited by - robvolk on 08/08/2002 09:09:46 |
 |
|
|
|
|
|