用系统的高速合并,能够正常编号。在窗口用按钮click来合并,生成的编号都是一个样。不知道为什么。
按钮代码:
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim mg As New Merger
mg.Format = "excel" '指定格式
mg.SourcePath = dlg.FileName
mg.SourceTableName = "sheet1$"
mg.DataTableName = "小包发货单"
mg.Merge()
End If
自动编号代码放在datacolchanged里,
Select e.DataCol.Name '自动生成子编码
Case "编号"
If e.DataRow.IsNull("编号") Then
e.DataRow("子编号") = Nothing
Else
Dim bh As String = e.DataRow("编号")
If e.DataRow("子编号").StartsWith(bh) = False '如果子编号前缀不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(子编号)","编号 = '" & bh & "' And [_Identify] <> " & e.DataRow("_Identify")) '取得该类别的最大编号
If max > "" Then '如果存在最大编号
Dim l As Integer = bh.Length
idx = CInt(max.Substring(l,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("子编号") = bh & Format(idx,"000")
End If
End If
End Select