vb vsflexgrid 导出excel后本来合并的单元格不合并了,怎么解决
展开全部
Sub ex_to()
On Error Resume Next
If VSFlexGrid1.TextMatrix(0, 1) <> "" Then
Dim l As Integer, s1 As String, s2 As String, s3 As String, s4 As String
Dim i As Long, k As Long, t As Long, s As Long
Dim xls As New Excel.Application 'EXCEL应用程序对象
Dim xbook As Excel.Workbook 'EXCEL工作薄对象
Dim xsheet As Excel.Worksheet 'EXCEL工作表对象
Set xbook = xls.Workbooks.Open(App.Path & "\1.xls")
Set xsheet = xbook.Worksheets(1)
s = 5 'Val(Trim(xsheet.Cells(1, 5))) - 1
With VSFlexGrid1
For i = 0 To .Rows - 1
For k = 0 To .Cols - 1
xsheet.Cells(i , k) = Trim(.TextMatrix(i, k) & "")
Next
Next
End With
For i = 2 To VSFlexGrid1.Rows - 1
s1 = xsheet.Cells(i, 1)
s4 = xsheet.Cells(i - 1, 1)
If s1 = s4 Then
xsheet.Cells(i, 1) = ""
End If
Next
l = 1 For i = 2 To VSFlexGrid1.Rows - 1
s1 = xsheet.Cells(i, 1)
If s1 <> "" Then
s2 = "a" & l
s3 = "a" & i - 1
xsheet.Range(s2 & ":" & s3).Select
xls.Selection.Merge
l = i
End If
Next
xls.Visible = True '显示Excel
Else
MsgBox "无内容输出!", 16, "输出失败:"
End If
End Sub
On Error Resume Next
If VSFlexGrid1.TextMatrix(0, 1) <> "" Then
Dim l As Integer, s1 As String, s2 As String, s3 As String, s4 As String
Dim i As Long, k As Long, t As Long, s As Long
Dim xls As New Excel.Application 'EXCEL应用程序对象
Dim xbook As Excel.Workbook 'EXCEL工作薄对象
Dim xsheet As Excel.Worksheet 'EXCEL工作表对象
Set xbook = xls.Workbooks.Open(App.Path & "\1.xls")
Set xsheet = xbook.Worksheets(1)
s = 5 'Val(Trim(xsheet.Cells(1, 5))) - 1
With VSFlexGrid1
For i = 0 To .Rows - 1
For k = 0 To .Cols - 1
xsheet.Cells(i , k) = Trim(.TextMatrix(i, k) & "")
Next
Next
End With
For i = 2 To VSFlexGrid1.Rows - 1
s1 = xsheet.Cells(i, 1)
s4 = xsheet.Cells(i - 1, 1)
If s1 = s4 Then
xsheet.Cells(i, 1) = ""
End If
Next
l = 1 For i = 2 To VSFlexGrid1.Rows - 1
s1 = xsheet.Cells(i, 1)
If s1 <> "" Then
s2 = "a" & l
s3 = "a" & i - 1
xsheet.Range(s2 & ":" & s3).Select
xls.Selection.Merge
l = i
End If
Next
xls.Visible = True '显示Excel
Else
MsgBox "无内容输出!", 16, "输出失败:"
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询