-- 作者:ouyangfenghuan
-- 发布时间:2018/10/24 23:32:00
--
谢谢
如果用代码导出表中处理汇总排序好的行要怎么写代码
我写的不能导出分组汇总行,请老师指正
Dim bh1 As String If Tables("订单跟踪表").Current Is Nothing Then Return \'当前表中无行时返回 Else bh1= Tables("订单跟踪表").Current("订单表序号") End If If bh1="" Then \'编号为空时返回 Return End If
Tables("生产日报表").Filter="" Tables("生产日报表").Filter="订单编号=\'" & bh1 & "\'and 辅助工艺 =false" Tables("生产日报表").Sort="起始时间"
Dim t As Table = Tables("生产日报表") Dim g As Subtotalgroup t.SubtotalGroups.Clear() \'定义客户分组 g = New Subtotalgroup \'定义一个新的分组 g.Aggregate = AggregateEnum.Sum \'统计类型为求和 g.GroupOn = "工序" \'分组列为客户 g.TotalOn = "实际产量" \'统计数量和金额列 g.Caption = "{0} 小计" \'设置标题 t.SubtotalGroups.Add(g) \'加到分组集合中 t.Subtotal(True) \'生成汇总模式
Dim Book As New XLS.Book(ProjectPath & "Attachments\\产品跟踪数量单.xls")\'调用模板 Dim fl As String = ProjectPath & "Reports\\产品跟踪数量单.xls" Book.Build() \'生成细节区
Dim dt As Table = Tables("生产日报表") \'提取并筛选流程表信息 Dim nms() As String = {"工序","日期","实际产量","机台","起始时间","结束时间","姓名"} \'要导出的列名 Dim caps() As String = {"工序","生产日期","良品数量","不良可用数量","报废/丢失数量","机台","起始时间","结束时间","姓名"} \'对应的列标题 Dim Sheet As XLS.Sheet = Book.Sheets(0) \'引用工作簿的第一个工作表
Dim n1 As Integer For i1 As Integer=0 To Sheet.Rows.Count-1 Dim mz As String= Sheet(i1, 0).Value If mz.Contains("工序") n1=i1+1 \'返回工艺标题行 Exit For End If If i1>50 Then MessageBox.Show("未找到表报的工序标题") Exit For End If Next
For r As Integer = 0 To dt.Rows.Count - 1 \'填入数据表的行数 For c As Integer = 0 To nms.length -1 \'Sheet.Rows(r +4).Height = 40 \'设置行的行高 Select Case c Case 0,1,2 Sheet(r +n1, c).Value = dt.rows(r)(nms(c)) \'输入数据 Case Else Sheet(r +n1, c+2).Value = dt.rows(r)(nms(c)) \'输入数据 End Select Next Next
Book.Save(fl) \'保存工作簿 Dim Proc As New Process \'打开工作簿 Proc.File = fl Proc.Start() dt.Filter = ""
|