以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 专业报表 合并单元格不生效 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=174372) |
||||
-- 作者:有点蓝 -- 发布时间:2022/1/12 15:10:00 -- 没看懂,黄色代码和合并单元格有什么关系?! |
||||
-- 作者:有点蓝 -- 发布时间:2022/1/12 16:02:00 -- http://www.foxtable.com/webhelp/topics/2049.htm |
||||
-- 作者:有点蓝 -- 发布时间:2022/1/12 16:55:00 -- 不止5楼的代码,帮助里要好几个地方和合并有关,学会理解代码 Dim doc As New PrintDoc Dim rt As New prt.RenderTable Dim tb As Table = Tables("订单") Dim ColNames As String() = New String(){"产品", "客户","单价","折扣","数量","金额","日期"} Dim MergeCols As Integer = 2 \'指定要合并的列数 tb.Sort = "产品,客户" \'根据合并列排序 rt.Width = "Auto" rt.SplitHorzBehavior = prt.SplitBehaviorEnum.SplitIfNeeded rt.Style.Font = tb.Font rt.Style.TextAlignVert = prt.AlignVertEnum.Center rt.RepeatGridLinesVert = True \'换页后重复表格线 For c As Integer = 0 To ColNames.Length - 1 Dim lr As Integer \' 用于保存合并区域的起始行 rt.Cells(0,c).Text = ColNames(c) rt.Cells(0,c).Style.TextAlignHorz = prt.AlignHorzEnum.Center rt.Cols(c).Width = tb.Cols(ColNames(c)).PrintWidth If tb.Cols(ColNames(c)).IsNumeric Orelse tb.Cols(ColNames(c)).IsDate Then rt.Cols(c).Style.TextAlignHorz = prt.AlignHorzEnum.Right End If For r As integer = 0 To tb.Rows.Count - 1 If c <= MergeCols - 1 then \'如果是要合并的列 Dim Merge As Boolean = True If r = 0 Then Merge = False 第一行默认不合并 Else For n As Integer = 0 To c If tb.Rows(r)(ColNames(n)) <> tb.Rows(r - 1)(ColNames(n)) 判断和上一行单元格数据是否一样,一样的就合并 Merge = False Exit For End If Next End If If Merge Then 如果需要合并 rt.Cells(lr,c).SpanRows = rt.Cells(lr,c).SpanRows + 1 设置合并 Else rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c)) rt.Cells(r + 1, c).VertSplitBehavior = prt.CellSplitBehaviorEnum.Copy \'换页 后重复单元格 lr = r + 1 End If Else rt.Cells(r + 1, c).Text = tb.Rows(r)(ColNames(c)) End If Next Next rt.Style.Gridlines.All = New prt.Linedef(Color.Gray) rt.CellStyle.Spacing.All = 0.5 rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.Center rt.RowGroups(0,1).Header = prt.TableHeaderEnum.All doc.Body.Children.Add(rt) doc.Preview() |
||||
-- 作者:有点蓝 -- 发布时间:2022/1/12 17:31:00 -- 请上传实例测试 |
||||
-- 作者:有点蓝 -- 发布时间:2022/1/13 9:57:00 -- 处理中,别急 |
||||
-- 作者:有点蓝 -- 发布时间:2022/1/13 13:30:00 --
|
||||
-- 作者:有点蓝 -- 发布时间:2022/1/15 13:44:00 -- 列名中间空格数量不一致 产品图片 Picture产品图片 Picture
|
||||
-- 作者:有点蓝 -- 发布时间:2022/1/15 14:58:00 -- 定义是在ColNames1 呀 If ColNames1(c) <>"产品图片 Picture"
|