如何在每行Excel文件中使用循环? [英] How To Use a Loop In Excel File Every Line?

查看:100
本文介绍了如何在每行Excel文件中使用循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含更多列的Excel文件,但我需要列名称,成本和时间



我需要逐行循环我的Excel但是当我有列名/成本/时间来保存变量中的值。



I have an Excel file with more Columns, but i need column NAME, Cost and Time

I need to loop in my Excel line by line but when i have Column Name/Cost/Time to save value in a variable.

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




        End If

    End If





如果是workBook.Worksheets.Count> 0然后我需要循环来自单元格的每个值。最后我计算了一个盒子里所有时间的平均值。



非常感谢



Where is If workBook.Worksheets.Count > 0 Then i need to loop every value from cell. At finally I calculated the average of all times in a box.

Thanks a lot

推荐答案

你可以使用Cells集合。工作表[0]。细胞(行,列)。



另外,使用intellisense自行查找这些内容。这是一个很好的学习方式。只需输入Worksheets [0]即可。并且你会看到intellisense弹出工作表的各种方法和属性。
You can use the Cells collection. Worksheets[0].Cells(row, column).

Also, use intellisense to find these things on your own. It's a great way to learn. Just type Worksheets[0]. and you'll see intellisense pop up with the various methods and properties of a worksheet.


Dim start = worksheet.Dimension.Start
Dim [_end] = worksheet.Dimension.[End]
For row As Integer = start.Row To [_end].Row
	' Row by row...
	For col As Integer = start.Column To [_end].Column
		' ... Cell by cell...
		Dim cellValue As Object = workSheet__1.Cells(row, col).Text
	Next
Next





来源 [ ^ ]

我们亲爱的Visual Studio有这个名为'intellisense'的强大功能。使用它进行一点探索。



-KR



Source[^]
And our dear Visual Studio has this great feature called 'intellisense'. Do little bit exploration using it.

-KR


Do currentWorksheet.Cells(i,1).Value< >没有什么



名称= currentWorksheet.Cells(i,1).Value

尝试

TimeCompletyDefinited = currentWorksheet。单元格(i,36).Value

Catch ex As Exception

结束尝试

If(currentWorksheet.Cells(i,4).Value )=已完成和(currentWorksheet.Cells(i,8).Value)=需要的列然后



a = a + currentWorksheet.Cells(i,35 ).Value

b = b + currentWorksheet.Cells(i,36).Value

c = c + currentWorksheet.Cells(i,38).Value



结束如果

i = i + 1

Loop
Do While currentWorksheet.Cells(i, 1).Value <> Nothing

Name = currentWorksheet.Cells(i, 1).Value
Try
TimeCompletyDefinited = currentWorksheet.Cells(i, 36).Value
Catch ex As Exception
End Try
If (currentWorksheet.Cells(i, 4).Value) = "Completed" And (currentWorksheet.Cells(i, 8).Value) = "Column Needed" Then

a = a + currentWorksheet.Cells(i, 35).Value
b = b + currentWorksheet.Cells(i, 36).Value
c = c + currentWorksheet.Cells(i, 38).Value

End If
i = i + 1
Loop


这篇关于如何在每行Excel文件中使用循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆