User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 402,067 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,581 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 1247 | Replies: 1
Reply
Join Date: Oct 2007
Posts: 23
Reputation: poonams is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
poonams's Avatar
poonams poonams is offline Offline
Newbie Poster

Help problem in importing table into Excel

  #1  
Dec 17th, 2007
hi
In my application i want to import table from Access to Excel.I have include Microsoft Web Browser to display the excel sheet .When i am running the application.It display the sheet.But One error is pop up"The file can not access,it being used by another process"

Can anyone give the sol.here is my code
  Try

            Dim excel As New Excel.ApplicationClass
            Dim wBook As Excel.Workbook
            Dim wSheet As Excel.Worksheet

            wBook = excel.Workbooks.Add()
            wSheet = wBook.ActiveSheet()
            filltemp()
            Cmd.CommandType = CommandType.Text
            'Cmd.CommandText = "Select * from SalRpt_temp"
            Cmd.CommandText = "SELECT  a.srno as Srno,a.ename as 'Name Of Employee',a.pdays as 'Present Day',a.desig as Designation ,a.bs as Basic,a.dp as DP,a.total as Total,a.hra as HRA,a.cla as CLA,a.ta as TA,a.npa as NPA,a.other as'Other Allowance',a.tal as 'Total Allowance',a.net as 'Net Claim',a.pt as 'PTax',a.it as 'Income Tax',a.sal as 'SalAdv',a.pf as PF,a.lic as LIC,a.bank as 'Bank Recov',a.tdeduct as 'Total Deduction',a.netsal as 'Net Salary' FROM SalRpt_temp a"
            Cmd.Connection = con

            adp.SelectCommand = Cmd
            adp.Fill(ds)
            Dim dt As System.Data.DataTable = ds.Tables(0)
            Dim dc As System.Data.DataColumn
            Dim dr As System.Data.DataRow
            Dim colIndex As Integer = 0
            Dim rowIndex As Integer = 1

            For Each dc In dt.Columns
                colIndex = colIndex + 1
                excel.Cells(1, colIndex) = dc.ColumnName
            Next

            For Each dr In dt.Rows
                rowIndex = rowIndex + 1
                colIndex = 0
                For Each dc In dt.Columns
                    colIndex = colIndex + 1
                    excel.Cells(rowIndex + 1, colIndex) = dr(dc.ColumnName)
                Next
            Next
            'AxWebBrowser1.Navigate("G:\Salary Package\salary.xls")
            wSheet.Columns.AutoFit()
            Dim strFileName As String = "G:\Salary Package\salary.xls"
            AxWebBrowser1.Navigate(strFileName)

            Dim blnFileOpen As Boolean = False
            Try
                Dim fileTemp As System.IO.FileStream = System.IO.File.OpenWrite(strFileName)
                fileTemp.Close()

            Catch ex As Exception
                blnFileOpen = False
            End Try

            If System.IO.File.Exists(strFileName) Then
                System.IO.File.Delete(strFileName)

            End If

            wBook.SaveAs(strFileName)
            excel.Workbooks.Open(strFileName)
            excel.Visible = True


        Catch ex As Exception
            con.Close()
            MsgBox(ex.Message)
        End Try
plz help me.My technology is vb.net2003 + ms access
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Posts: 4,711
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 309
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: problem in importing table into Excel

  #2  
Dec 17th, 2007
>The file can not access,it being used by another process

I've not looked at your code, but that generally means you're trying to do stuff with the file whilst it is already open?
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb VB.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the VB.NET Forum

All times are GMT -4. The time now is 12:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC