【发布时间】:2014-02-03 05:31:39
【问题描述】:
我正在尝试使用 MSSQL 中的数据生成 Excel 报告。它在我的电脑(服务器)和所有客户端上完美运行,除了那些安装了 Windows 8 的电脑(安装了 MS Office 2010)。我在 WinxP/win7 客户端 PC 中测试了该程序,两者都能够生成安装的 excel 报告(MS office 2007)。问题是否可能是 MS Office 的不同版本?这是我的代码示例。再次,它在我的服务器 PC 和除 win8 机器之外的其他客户端 PC 上运行良好。
Private Sub Report_JSIADGTAMKOR()
On Error Resume Next
Dim consigneeName As String
If cmboAccount.Text = "AMKOR" Then
consigneeName = "AMKOR"
ElseIf cmboAccount.Text = "JSI-CIRTEK" Then
consigneeName = "JSI-CIRTEK"
ElseIf cmboAccount.Text = "JSI-LATTICE" Then
consigneeName = "JSI-LATTICE"
Else
consigneeName = "ANALOG DEVICES GEN. TRIAS - JSI"
End If
Wbook = createExcel.Workbooks.Add
Wsheet = Wbook.Worksheets(1)
If Format(dteFrom.Value, "MM-dd-yyyy") = Format(dteTo.Value, "MM-dd-yyyy") Then
DateRange = Format(dteTo.Value, "MM-dd-yyyy")
Else
DateRange = Format(dteFrom.Value, "MM-dd") & " To " & Format(dteTo.Value, "MM-dd-yy")
End If
Wbook.Worksheets(1).Name = cmboAccount.Text & "-SR " + DateRange.ToString
Wsheet.Cells(1, 1).Value = "MAKATI TRANSFORWARDERS CORP."
Wsheet.Cells(1, 1).Font.Bold = True
Wsheet.Cells(1, 1).Font.Size = 10
Wsheet.Cells(3, 1).Value = "Daily Status Report - " & DateRange.ToString
Wsheet.Cells(3, 1).Font.Bold = True
Wsheet.Cells(3, 1).Font.Size = 10
Wsheet.Cells(5, 1).Value = consigneeName
Wsheet.Cells(5, 1).Font.Bold = True
Wsheet.Cells(5, 1).Font.Size = 10
Wsheet.Cells(7, 1).Value = "Prepared by: Jasmin"
Wsheet.Cells(7, 1).Font.Bold = True
Wsheet.Cells(7, 1).Font.Size = 10
Wsheet.Cells(9, 1).Value = "HAWB"
Wsheet.Cells(9, 2).Value = "INVOICE VALUE"
Wsheet.Cells(9, 3).Value = "DUTIABLE VALUE"
Wsheet.Cells(9, 4).Value = "CUSTOMS DUTY"
Wsheet.Cells(9, 5).Value = "LANDED COST"
Wsheet.Cells(9, 6).Value = "ENTRY NO"
Wsheet.Cells(9, 7).Value = "IP NO"
Wsheet.Cells(9, 8).Value = "DESCRIPTION"
Wsheet.Cells(9, 9).Value = "REMARKS"
For Me.itemCounter = 1 To 9
Wsheet.Cells(9, itemCounter).Font.Bold = True
Next itemCounter
rs = New ADODB.Recordset
sql = "Select * From tblDocEntry Where CONVERT(datetime, DateEntry) Between '" & Format(dteFrom.Value, "MM/dd/yyyy") & "' AND '" & Format(dteTo.Value, "MM/dd/yyyy") & "' and ClientCode='" & Trim(cmboAccount.Text) & "' order by DateEntry"
With rs
.Open(sql, cn, CursorTypeEnum.adOpenDynamic, LockTypeEnum.adLockOptimistic)
rowCounter = 10
itemCounter = 1
While .EOF = False
Dim chkBLHAWBno As String
chkBLHAWBno = .Fields("BLHAWBNo").Value
Dim subHAWB As String
subHAWB = chkBLHAWBno.ToString.Substring(0, 3)
If IsExist("tblOmit", "OmitHAWB", subHAWB) Then
Dim len As String = chkBLHAWBno.ToString.Trim.Length
Wsheet.Cells(rowCounter, 3).Value = chkBLHAWBno.ToString.Substring(4, len - 4)
Else
Wsheet.Cells(rowCounter, 3).Value = .Fields("BLHAWBNo").Value
End If
Wsheet.Cells(rowCounter, 1).NumberFormat = "0000"
Wsheet.Cells(rowCounter, 2).Value = .Fields("FMVUSD").Value
Wsheet.Cells(rowCounter, 2).NumberFormat = "0.00"
Wsheet.Cells(rowCounter, 3).Value = .Fields("PESOVALUE").Value
Wsheet.Cells(rowCounter, 3).NumberFormat = "0.00"
Wsheet.Cells(rowCounter, 4).Value = .Fields("DUTYAMOUNT").Value
Wsheet.Cells(rowCounter, 4).NumberFormat = "0.00"
Wsheet.Cells(rowCounter, 5).Value = .Fields("LANDEDCOST").Value
Wsheet.Cells(rowCounter, 5).NumberFormat = "0.00"
Wsheet.Cells(rowCounter, 6).Value = .Fields("ENTRYNO").Value
Wsheet.Cells(rowCounter, 7).Value = .Fields("IPNO").Value
Wsheet.Cells(rowCounter, 8).Value = Trim(.Fields("GoodDesc").Value)
Wsheet.Cells(rowCounter, 9).Value = .Fields("DOCREMARKS").Value
rowCounter = rowCounter + 2
itemCounter = itemCounter + 1
.MoveNext()
End While
.Close()
End With
rs = Nothing
Wsheet.Cells(rowCounter + 1, 1).Value = "Total Number of Entry/ies: " & (itemCounter - 1)
Wsheet.Cells(rowCounter + 2, 1).Value = "Date Printed: " + Format(Now, "MM/dd/yyyy") + " - " + Format(Now, "hh:mm:ss tt")
Wsheet.Cells(rowCounter + 1, 1).Font.Bold = True
Wsheet.Cells(rowCounter + 2, 1).Font.Bold = True
Wsheet.Columns.AutoFit()
Wsheet.Rows.AutoFit()
'Wsheet.Cells.NumberFormat = "0000"
filesavepath = AppPath & "\Status Reports\" & Trim(cmboAccount.Text) & " - Status Report " + DateRange.ToString + ".xls"
Wbook.SaveAs(filesavepath)
Wbook.Close(True)
System.Diagnostics.Process.Start(filesavepath)
Wbook = Nothing
Wsheet = Nothing
MsgBox("Report Successfully Generated", vbOKOnly + vbInformation, "System Alert")
End Sub
抛出的错误是这样的: “连接超时:登录后阶段超时时间已过。连接可能在等待服务器完成登录过程并响应时超时。或者它可能在尝试创建多个活动连接时超时。”
任何关于我的问题的帮助将不胜感激
【问题讨论】:
-
@Damith 对我不起作用。同样,我的问题只是在 win8 机器上,其他运行 xp/win7 的客户端 PC 根本没有这个问题。