我遇到了XLSM Excel的问题,我希望按条件获取一些数据。
在图片中我有“名称”和“状态”,如果状态为“已完成”,我想在“时间装配 - >后装配”中取值,其值为“1.11”。对于“Time Assembly”的每个值,我最终想要做媒体。
我的代码:
If FileUpload1.HasFile = False Then
Exit Sub
Else
Dim FileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim Extension As String = Path.GetExtension(FileUpload1.PostedFile.FileName)
'Dim FolderPath As String = ConfigurationManager.AppSettings("Upload")
Dim FilePath As String = Server.MapPath("~") & "\Upload\" & FileName
FileUpload1.SaveAs(FilePath)
Dim existingFile = New FileInfo(FilePath)
Dim pack As ExcelPackage = New ExcelPackage(existingFile)
Dim workBook As ExcelWorkbook = pack.Workbook
If workBook.Worksheets.Count > 0 Then
Dim currentWorksheet As ExcelWorksheet = workBook.Worksheets.First()
End If
End If
在那个“if”中,我希望在那个条件之后逐行读取Excel。
非常感谢!
答案 0 :(得分:0)
尝试找到工作表中的最后一行并使用for循环来迭代条件
Sub test()
Dim lastRow As Long
Dim workBook As workBook
workBook = ThisWorkbook
lastRow = workBook.ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For i = 3 To lastRow
'for checking value in the 4 column(D column)
If (workBook.ActiveSheet.Cells(i, 4).Value) = "completed" Then
workBook.ActiveSheet.Cells(i, 6).Value = "xx"
End If
'for adding value in the 6 column
Next
End Sub