Dim adoConn As New ADODB.Connection
adoConn.ConnectionString = ConnString
adoConn.Open
Dim rs As Recordset
rs.CursorLocation = adUseClient
rs.Open strSQL, adoConn
Dim i As Integer,j As Integer
For i = 0 To rs.Fields.Count - 1
ActiveSheet.Cell(i, 1) = rs.Fields(i).Name
Next i
For i = 0 To rs.Fields.Count - 1
For j = 0 To rs.RecordCount - 1
ActiveSheet.Cells(i, j + 2) = rs.Fields(j).Value
Next j
rs.MoveNext
Next i
Range(Cells(1,1),Cells(i,j)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
dim wkExcel as new Excel.Application
....
'上面为打开EXCEL
for i 0 to Max_Row
for j 1 to Max_Col
With Application.ThisWorkbook.ActiveSheet.Cells(i,j)
.Borders(xlEdgeLeft).LineStyle=xlContinous
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeLeft).ColorIndex = xlAutomatic