使用VB.NET读取excel数据列 [英] reading excel data by column using VB.NET
问题描述
我从未从VB.NET中读取excel文件,所以如果有什么事情发生之前,我很抱歉。
我正在从供应商的ftp服务下载一个.csv文件有8列
(样式# - mfr.item# - 描述 - 金属类型 - 可用性 - 中心重量 - 总重量 - 零售价值)
我是尝试检索所有数据,如下列样式#和零售价值
有大约4,649行
我不知道该怎么做。 >
我使用microsoft.office.interop.excel加载excel文件:
Dim eApp As excel.Application
Dim eBook As excel.Workbook
Dim eSheet As excel.Worksheet
Dim eCell As excel.Range
eApp = New excel。应用程序
eBook = eApp.Workbooks.Open(localFile)
eSheet = eBook.Worksheets(1)
eCell = eSheet.UsedRange
任何人都可以帮助我下一步需要做什么?我已经浏览了google几个小时了,没有任何工作,只是返回一个对象名称。
谢谢
你几乎在那里!这里有两种方法。
方式#1:在 eCell = eSheet.UsedRange
之后添加以下内容:/ p>
Dim eCellArray as System.Array = eCell.Value
然后通过 eCellArray(r,c)
获取值,其中r是行,c是列(每个开始从1)。
方式#2:使用此表达式获取单元格的值:
CType(eCell(r,c),Excel.Range).Value'对于Option Strict,或者只是让IntelliSense工作。
或简单地
code> eCell(r,c).Value
HTH
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
Dim 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
这篇关于使用VB.NET读取excel数据列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!