excel
  • vb.net
  • for-loop
  • oledb
  • 2016-10-06 21 views 0 likes 
    0

    我工作的一個自動化的合規性工具,並碰到了下面的問題一個項目:VB.net僅Excel填補每

    我生成一個Excel工作表,目前看起來像這樣(使用虛擬由於公司數據的數據):

    enter image description here

    但實際上應該是這個樣子(不是實際的數據):

    enter image description here

    的信息被用在函數下面的查詢稱爲getRightsForPath()拉出一個數據庫:

    "SELECT DUMPSEC.rights 
    FROM DUMPSEC 
    WHERE DUMPSEC.location ='" & sql2 & "' 
    AND DUMPSEC.members = '" & sql1 & "'" 
    

    ,這是應該照顧的權利被添加到右邊的單元格循環:

    For i = 1 To groupCounter Step +1 
        Dim rights = getRightsForPath(sourceLocation, xlWorksheet.Cells(2, i + 1).Value, xlWorksheet.Cells(Row, 1).Value) 
    
         Do While rights.Read() 
    
          xlWorksheet.Cells(Row, i + 1) = rights("rights") 
          //MessageBox.Show(locations("location") & ", " & groupOwnerOf("groupname") & ", " & rights("rights")) 
    
         Loop 
    
    Next 
    Row += 1 
    

    回答

    0

    沒關係,搞明白了我自己,我忘了把它們都放在一個循環,並檢查所要做的行(如以下代碼所示)

    For Row = 3 To locationCount Step +1 
        For i = 2 To groupCounter + 1 Step +1 
         Dim rights = getRightsForPath(sourceLocation, xlWorksheet.Cells(2, i).Value, xlWorksheet.Cells(Row, 1).Value) 
         Do While rights.Read() 
          xlWorksheet.Cells(Row, i) = rights("rights") 
         Loop 
        Next 
    Next 
    
    相關問題