如何在Excel中定义行计数 [英] How define rows count in Excel
本文介绍了如何在Excel中定义行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Worksheet mySheet = workbook.Sheets[1];
var range = mySheet.Count;
这段代码显示了所有行数/我只需要具有数据的行
This code show me all count of rows/ I need only rows thats have data
推荐答案
这将在Excel中获得行数和库仑数.Sheet:
This would get the row and coulum count in the Excel.Sheet:
Worksheet mySheet = workbook.Sheets[1];
if (sheet != null)
{
columns = mySheet.Columns.Count;
rows = mySheet.Rows.Count;
}
如果您使用的是.NET,则应将数据读入这样的数组中:
If you are in .NET you should read the data into an array like this:
Dim filename As String = path & "\YourFile.xlsx"
' Create new Application.
Dim excel As Excel.Application = New Excel.Application
' Open Excel spreadsheet.
Dim w As Excel.Workbook = excel.Workbooks.Open(filename)
Dim sheet As Excel.Worksheet = w.Sheets(1)
Dim usedRange As Excel.Range = sheet.UsedRange
Dim darray(,) As Object
darray = CType(usedRange.Value, Object(,))
Dim rows As Integer = darray.GetUpperBound(0)
Dim cols As Integer = darray.GetUpperBound(1)
For i As Integer = 1 To rows
For j As Integer = 1 To cols
'Get the cell info here....
Next
Next
w.Close()
这篇关于如何在Excel中定义行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文