Solved

Creating and Deleting worksheets in Excel usign Visual Studio

Posted on 2010-08-30
1
259 Views
Last Modified: 2013-11-27
I want to export data to an existing excel spreadsheet and into a specific worksheet. Each time I will need to delete and then re-create the worksheet. But I do not know what the command is for either. I tried the following to create it and it processed thru without error but i do not see it when I open the spreadsheet (it did not previously exist). I am using Visual Studio 2008.

        Dim SQL1 = "Create Table [TestData2]"

        Dim ExcelConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & “c:\test.xls” & ";" & _
        "Extended Properties=""Excel 8.0;HDR=YES""")

        ExcelConnection.Open()
        Dim ExcelCommand As New System.Data.OleDb.OleDbCommand(SQL1, ExcelConnection)
        ExcelCommand.ExecuteNonQuery()


0
Comment
Question by:PHFrench
1 Comment
 
LVL 96

Accepted Solution

by:
Bob Learned earned 125 total points
ID: 33613007
If you need to recreate the worksheet you need to

1) Drop the table

DROP TABLE [Sheet1$]

2) Create the table

CREATE TABLE [Sheet1$]([Full Name] char(255),[Type] char(255),[Date] char(255),[Num] char(255),[Name City] char(255),[Name State] char(255),[Name Zip] char(255),[Memo] char(255),[Name Account #] char(255),[Name] char(255),[UPC Code] char(255),[Item Description] char(255),[Rep] char(255),[Qty] char(255),[Sales Price] char(255),[Amount] char(255))
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now