---
 
 
---
 
 
Smilepk Home | Tips Home | Contact | Games | Themes | Wallpapers | Videos
GOOGLE
Free SEO, Web Related Tips
    Web Hosting Guide
    SEO Articles, Tips
    Earn With Google
    Hot n Top Tips
    Mix Web Special
    Miscellaneous Tips
---
Free Windows xp Tips
    User Interface
    Usability Tweaks
    Security Tricks
    Hardware Tweaks
    Internet & Network
    System Performance
    Miscellaneous Tips
    Software Tips
---
Today World Tips
    Travelling Tips
    Cooking Tips
    Credit Card Tips
    Photography Tips
    Handwriting Tips
    Student Visa Tips
    Resume Tips
    Aloe Vera Tips
    Weightloss Tips
    Beauty Tips
    Mobile Codes Tips
---
Free Other Categories Tips
    PC Buying Tips
    System Tune-Up
    MS Office Tips
    Security Alerts
    Database Tips
    Registry Tricks
    Pc Troubleshooting
    Backup Tricks
    Printing Tips
    Cisco Router Tips
    Glossaries...
    Laptop Tricks
    PC Cleaning Tips
    System FAQs
    Internet Tips
    Windows Vista Tips
---
Free Broadband Tips
    ISP Tricks
    Wireless Tips
    VPN Tricks
    Mobile Tips
    ATM Tips Tricks
    Optic Fiber Tips
    Cable Net Tweaks
    DSL Tips Tricks
    Projector Tips
   Truncating Data When Exporting to Excel
     Home   Database Tips  Development Tips
----

Q
I built a Data Transformation Services (DTS) package that exports data from a table in SQL Server 7.0 to a spreadsheet in Microsoft Excel. The package's first run works fine, but subsequent runs just append the data to the spreadsheet instead of replacing it in the spreadsheet. How can I avoid this problem?

A
It sounds like you need to execute a TRUNCATE statement, then create new inserts. You can accomplish these steps easily in two ways: by using the automation model in Excel to empty the spreadsheet, or by superimposing a blank copy of the Excel spreadsheet on top of the populated spreadsheet by using a small script such as the example in Listing 1.

LISTING 1: Sample Script That Superimposes a Blank Copy of an Excel Spreadsheet on Top of a Populated Spreadsheet

Dim sDBFileName
Dim sTemplateFile
Dim oFSO
sDBFileName = "d:\data\acc_demo.xls"
sTemplateFile = "d:\data\acc_temp.xls"
SET oFSO = CreateObject("Scripting.FileSystemObject")
'If the file exists, delete it.
IF(oFSO.FileExists( sDBFileName )) THEN
oFSO.DeleteFile( sDBFileName )
END IF
'Optionally, copy from another file.
oFSO.CopyFile sTemplateFile, sDBFileNam
eSET oFSO = Nothing