以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请老师看一下这代码哪里出了问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=134743)

--  作者:ls93005
--  发布时间:2019/5/5 18:06:00
--  请老师看一下这代码哪里出了问题
Dim bok As New XLS.Book(ProjectPath & "Attachments\\路缘石质量检验评定表_汇总_模板.xlsx") 
Dim sht As XLS.Sheet = Bok.Sheets(0)

Dim kxs As List(of String) = DataTables("路缘石检查数据").GetValues("公里桩")
Dim buwei() As String = {"右侧" , "左侧"}
Dim shtrow() As Integer= {7,11,13}
For ix As Integer = 0 To kxs.Count-1
    For bw As Integer = 0 To 1
        For Index As Integer = 0 To 2
            Dim xcs As List (of DataRow) = DataTables("路缘石检查数据").Select("[工程部位] = \'" & buwei(bw) & " \'And [项次] = \'" & Index+1 & "\' And [公里桩] = \'" & kxs(ix) & " \' ")
            If xcs.Count > 0 Then
                For i0 As Integer = 0 To xcs.Count-1
                    Dim cov As Double
                    Double.TryParse(xcs(i0)("数据内容"),cov)
                    If i0 <= 9 Then
                        sht(shtrow(Index),8+i0).Value = cov
                    ElseIf i0 > 9 And i0 <= 19 Then
                        sht(shtrow(Index)+1,8+(i0-10)).Value = cov
                    ElseIf i0 > 19  Then
                        Exit For
                    End If
                Next
                sht(3,5).Value = "工程部位:" & buwei(bw)
                sht(3,2).Value =  kxs(ix) 
                Bok.Save(ProjectPath & "Reports\\LYJC_" & kxs(ix) & "_" & buwei(bw) & ".xlsx")
                
            End If
        Next
    Next
Next


以上代码,如果不加入标红部分的循环,直接输入固定值,则最后生成的EXCLE文件正确。
若加入以上循环,最后生成的EXCEL就会把其他{公里桩}的数据也插入到最后生成的文件中。

--  作者:有点甜
--  发布时间:2019/5/5 18:13:00
--  

你这里得到的,是所有的值 Dim kxs As List(of String) = DataTables("路缘石检查数据").GetValues("公里桩")

 

你希望得到哪个值?或者哪些值?逻辑是什么?


--  作者:ls93005
--  发布时间:2019/5/5 18:20:00
--  
对的,所有不重复的值。 满足select条件的都单独生成一个excel
--  作者:有点甜
--  发布时间:2019/5/5 18:31:00
--  

试试

 

 


Dim kxs As List(of String) = DataTables("路缘石检查数据").GetValues("公里桩")
Dim buwei() As String = {"右侧" , "左侧"}
Dim shtrow() As Integer= {7,11,13}
For ix As Integer = 0 To kxs.Count-1
    Dim bok As New XLS.Book(ProjectPath & "Attachments\\路缘石质量检验评定表_汇总_模板.xlsx")
    Dim sht As XLS.Sheet = Bok.Sheets(0)
    For bw As Integer = 0 To 1
        For Index As Integer = 0 To 2
            Dim xcs As List (of DataRow) = DataTables("路缘石检查数据").Select("[工程部位] = \'" & buwei(bw) & " \'And [项次] = \'" & Index+1 & "\' And [公里桩] = \'" & kxs(ix) & " \' ")
            If xcs.Count > 0 Then
                For i0 As Integer = 0 To xcs.Count-1
                    Dim cov As Double
                    Double.TryParse(xcs(i0)("数据内容"),cov)
                    If i0 <= 9 Then
                        sht(shtrow(Index),8+i0).Value = cov
                    ElseIf i0 > 9 And i0 <= 19 Then
                        sht(shtrow(Index)+1,8+(i0-10)).Value = cov
                    ElseIf i0 > 19  Then
                        Exit For
                    End If
                Next
                sht(3,5).Value = "工程部位:" & buwei(bw)
                sht(3,2).Value =  kxs(ix)
                Bok.Save(ProjectPath & "Reports\\LYJC_" & kxs(ix) & "_" & buwei(bw) & ".xlsx")
               
            End If
        Next
    Next
Next


--  作者:ls93005
--  发布时间:2019/5/5 19:01:00
--  
非常感谢!!!
一下午的问题老师一句话点醒,您真是我的偶像!