Dim t1 As DataTable = DataTables("Sheet3")
Dim pzh As new List(of String)
pzh = t1.GetValues("凭证号","对方科目 is null")
Dim Dic As new Dictionary(of String,Double)
Dim dfhj As Double
Dim Dicrow As new Dictionary(of String,List(of DataRow))
Dim Dicrow1 As new Dictionary(of String,List(of DataRow))
For Each pz As String In pzh
dfhj = t1.Compute("sum(贷方)","凭证号 = '" & pz & "'")
dic.Add(pz,dfhj)
Dim jh1 As new List(of DataRow)
Dim jh2 As new List(of DataRow)
jh1 = t1.Select("借方 is not null" & " and 借方 <> 0 " & " And 凭证号 = '" & pz & "'","_sortkey")
jh2 = t1.Select("贷方 is not null" & " and 贷方 <> 0 " & " And 凭证号 = '" & pz & "'","_sortkey")
Dicrow.Add(pz,jh1)
Dicrow1.Add(pz,jh2)
Next
For Each pz As String In pzh
Dim hj As Double
hj = dic(pz)
For Each a As DataRow In Dicrow(pz)
a("凭证号") = pz & "拆"
For Each b As DataRow In Dicrow1(pz)
Dim tr As DataRow = t1.AddNew()
tr("一级科目名称") = a("一级科目名称")
tr("借方") = a("借方") * b("贷方")/hj
tr("对方科目") = b("一级科目名称")
tr("凭证号") = pz
b("凭证号") = pz & "拆"
Next
Next
Next