Skipping a column in FileHelper
Asked Answered
P

2

10

Using the FileHelper library for .Net, can I somehow skip a number of columns from the source file?

According to docs and samples, I have to add fields for all columns. Alas, I have an excel sheet with 216 columns to import, from which as few as 13 are necessary.

Peanut answered 9/12, 2008 at 7:32 Comment(0)
T
10

I have the same situation, and question. Searching the forums at filehelpers.net, I found this thread (from 2007?!) with a response by Marcos himself:

Question:

In a delimited length layout, is it possible to skip some fields? For example:
ExternalSysId|ExportDate|FirstName|LastName
I only want FirstName and LastName, and don't want to clutter up my code with "dummy" fields?

Response:

The library dont have a built in feature for this.

You can make the fields private, the library will read the values, but you dont see them from your code =) If in the future you need these fields you can meke them public

So, using the Record Class Wizard to reduce the amount of required typing, and then making unnecessary fields private, looks like the best option at this point.

Teletype answered 3/8, 2009 at 21:55 Comment(0)
H
6

You must add the fields as private, and can use also the Attribute

FieldValueDiscarded

To avoid the library store the read values in the fields

Heir answered 3/8, 2015 at 13:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.