'*****************************
'*****************************
'通 过 发 送 到MICROSOFT EXCEL 实 现 表 格 打 印
'*****************************
Public Function SendExcel(mFlex As MSFlexGrid, title As String, sumRow As Integer, sumCol As Integer)
On Error GoTo s1
Ax = 0
By = 0
Dim i As Integer
Dim j As Integer
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim str(21) As String
Dim strT(21) As String
Dim intT(21) As String
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Add
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, 1) = title
'生成表格
For i = 0 To sumRow - 1
mFlex.row = i
For j = 0 To sumCol - 1
mFlex.col = j
If IsNull(mFlex.Text) = False Then
If strT(j) = "" Then
If mFlex.MergeCol(j) = True Then
str(j) = Chr(65 + j)
strT(j) = Trim(mFlex.Text)
intT(j) = i + 3
End If
xlSheet.Cells(i + 3, j + 1) = Trim(mFlex.Text)
Else
If strT(j) <> Trim(mFlex.Text) Then
xlSheet.Cells(i + 3, j + 1) = Trim(mFlex.Text)
strT(j) = Trim(mFlex.Text)
End If
End If
End If
Next j
Next i
Ax = sumRow
By = sumCol
Dim LeftCol As Integer
On Error GoTo s1
'生成边框
If By <= 26 Then
xlApp.Range("A3:" & Chr(64 + By) & Ax + 2).Select
Else
LeftCol = By / 26
If By = 26 * LeftCol Then
i = 26
Else
i = 0
End If
xlApp.Range("A3:" & Chr(64 + LeftCol) & Chr(64 + By - 26 * LeftCol + i) & Ax + 2).Select
End If
xlApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
xlApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With xlApp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With xlApp.Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
Exit Function
s1:
MsgBox Err.Description
End Function