vb.net - skip first row when reading excel CSV file -
i found how in several languages not in .net (specifically vb.net). using oledbcommand read both csv , excel files. in case of excel can skip first row , select second row onwards specifying range of cells. in case of csv, not sure how it. current code looks like:
dim cmd oledbcommand = new oledbcommand("select * [" + path.getfilename(filename) + "]", cn)
here give file, not sheet. bit stuck.
from experience reading text file restrictive. allows read whole file, because can't specify table name. might better of reading each line , making table rows , adding them table. if first row headers can use make columns, otherwise hard code columns.
here's simple little method fills datatable data .csv file, should able use:
private sub getdata(byref dt datatable, filepath string, optional byval header boolean = true) dim fields() string dim start integer = cint(header) * -1 if not file.exists(filepath) return end if dt.clear() dim lines() string = file.readalllines(filepath) if cbool(start) andalso dt.columns.count = 0 lines(0) = lines(0).replace(chr(34), "") each h string in lines(0).split(",") dt.columns.add(h) next end if = start lines.count - 1 fields = lines(i).split(",") dt.rows.add(fields) next end sub
Comments
Post a Comment