Private Sub Form_Load()
'存字段长度值
'Dim RS As New ADODB.Recordset
' RS.CursorLocation = adUseClient
' RS.Open "select * from Employees", Cn, adOpenStatic, adLockOptimistic
' Dim xlApp As Excel.Application
' Dim xlBook As Excel.Workbook
' Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
' With RS
' If .RecordCount < 1 Then
' MsgBox ("没有记录!")
' Exit Sub
' End If
' xlSheet.Cells(1, 4).Value = .Fields("EmployeeID")
' xlSheet.Cells(2, 1).Value = .Fields("LastName")
' xlSheet.Cells(2, 9).Value = .Fields("FirstName")
' xlSheet.Cells(3, 1).Value = .Fields("Title")
xlSheet.Cells(1, 1).Value = "安徽"
xlSheet.Cells(1, 2).Value = "合肥"
xlSheet.Cells(2, 1).Value = "安徽"
xlSheet.Cells(2, 2).Value = "芜湖"
xlSheet.Cells(3, 1).Value = "安徽"
xlSheet.Cells(3, 2).Value = "蚌埠"
'合并单元格
'Dim nIcol As Integer
xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(3, 1)).Select
With xlApp.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
'网格线
With xlSheet
' .Range(.Cells(1, 1), .Cells(3, 1)).Font.Name = "黑体"
'设标题为黑体字
.Range(.Cells(1, 1), .Cells(3, 1)).Font.Bold = True
'标题字体加粗
.Range(.Cells(1, 1), .Cells(3, 1)).Borders.LineStyle = xlContinuous
'设表格边框样式
End With
'显示表格
Dim ExclFileName As String
ExclFileName = App.Path & "\箱单" & ".xls"
If Dir(ExclFileName) <> "" Then
Kill ExclFileName
End If
xlSheet.SaveAs (ExclFileName)
xlApp.Application.Visible = True
'交还控制给Excel
' xlSheet.PrintPreview
' xlApp.Application.Quit
' xlApp.Quit
' End With
End Sub