vb vsflexgrid 导出excel后本来合并的单元格不合并了,怎么解决

上图为我在vsflexgrid里的样子,但是导出来下却成了下面的样子,怎么解决呢?... 上图为我在vsflexgrid里的样子,但是导出来下却成了下面的样子,怎么解决呢? 展开
 我来答
iisheng
2012-10-16 · TA获得超过308个赞
知道小有建树答主
回答量:531
采纳率:100%
帮助的人:481万
展开全部
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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式