开发者

reading excel data by column using VB.NET

I have never read from an excel file in VB.NET before so sorry if anything is off.

I am downloading an .csv file from a vendors ftp service that has 8 columns ( style # - mfr.item # - description - metal type - availability - center weight - total weight - retail value )

I am trying to retrieve all data in the rows bellow style # and retail value there are roughly 4,649 rows

I am not sure how to do this.

I load the excel file using the microsoft.office.interop.excel:

Dim eApp As excel.Application
Dim eBook As excel.Workbook
Di开发者_如何学Pythonm eSheet As excel.Worksheet
Dim eCell As excel.Range

eApp = New excel.Application
eBook = eApp.Workbooks.Open(localFile)
eSheet = eBook.Worksheets(1)
eCell = eSheet.UsedRange

Can anyone help me on what I need to do next? I have browsed google for a few hours now and have not gotten anything to work, just return an object name.

Thanks


You are so almost there! Here are two ways.

Way #1: Add the following, after the eCell = eSheet.UsedRange:

Dim eCellArray as System.Array = eCell.Value

Then get the values via eCellArray(r,c), where r is the row and c is the column (each starting from 1).

Way #2: Use this expression to get the value of a cell:

CType(eCell(r,c),Excel.Range).Value ' For Option Strict, or just to get IntelliSense to work.

or simply

eCell(r,c).Value

HTH


You can, for example, access the cells in a range like this:

Dim iRow as Integer = 1
Dim iCol as Integer
Dim rng as Excel.Range = getYourRangeFromSomewhere()
Dim rngCell as Excel.Range

For iCol = 1 To 10 
   rngCell = rng.Cells(iRow,iCol)
   Debug.Print rngCell.Value
Next
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜