各位高手:还是excel报表的问题,提示:拒绝访问,Dim excelapp As New Excel.Application,请各位好心人帮帮我,我将原代码帖出来.
各位高手:还是excel报表的问题,提示:拒绝访问,Dim excelapp As New Excel.Application,请各位好心人帮帮我,我将原代码帖出来:
Dim ss As Integer
Dim sstt, stt01 As String
Dim tt As Integer
Dim dateA As String
Dim dateB As String
Dim conn As New SqlClient.SqlConnection("server=wchen;uid=sa;pwd=1;database=wwwddd")
Dim sqlcmd As SqlClient.SqlCommand
Dim sqlrd As SqlClient.SqlDataReader = Nothing
Dim excelapp As New Excel.Application
Dim ssbb As Excel.Workbook
Dim aabb As Excel.Worksheet
Dim ii As Integer = 4
ssbb = excelapp.Workbooks.Open("c:\abc.xls")
aabb = CType(ssbb.Worksheets("Sheet1"), Excel.Worksheet)
Dim sqlcmdtxt As String = "select * from CssbbHistoryZ order by 序号 "
''加入内容
aabb.Range("A5:T150").Value = ""
Try
sqlcn2.Open()
sqlcmd = New SqlClient.SqlCommand(sqlcmdtxt, sqlcn2)
sqlrd = sqlcmd.ExecuteReader()
While sqlrd.Read
ii = ii + 1
aabb.Cells(ii, 1) = sqlrd.GetValue(0)
aabb.Cells(ii, 2) = sqlrd.GetValue(1)
aabb.Cells(ii, 3) = sqlrd.GetValue(2)
aabb.Cells(ii, 4) = sqlrd.GetValue(3)
aabb.Cells(ii, 5) = sqlrd.GetValue(4)
aabb.Cells(ii, 6) = sqlrd.GetValue(5)
aabb.Cells(ii, 7) = sqlrd.GetValue(6)
aabb.Cells(ii, 8) = sqlrd.GetValue(7)
aabb.Cells(ii, 9) = sqlrd.GetValue(8)
aabb.Cells(ii, 10) = sqlrd.GetValue(9)
aabb.Cells(ii, 11) = sqlrd.GetValue(10)
aabb.Cells(ii, 12) = sqlrd.GetValue(11)
End While
sqlrd.Close()
Catch ex As Exception
MsgBox(Err.ToString)
Finally
If sqlcn2.State = ConnectionState.Open Then
sqlcn2.Close()
End If
End Try
''以上加入内容
excelapp.Visible = True
aabb.Activate()
aabb.Select()
aabb = Nothing
excelapp = Nothing
GC.Collect()