我编写了一个似乎正在使用的程序,但是目前它的设置方式我必须为我可能阅读的每种不同类型的CSV文件创建一个新的子程序。 我们的模板CSV永远不会改变。 我想知道的是你有一个定义列信息的文本文件吗?而不是必须创建一个具有不同格式的新子例程。 基本上它是一个CSV读取器,它读取文件并将信息列放入我们要求的格式。这是一个测试样本
I've written a program that seems to be growing in use, but currently the way it's setup I have to create a new sub routine for each different type of CSV file I may read. Our template CSV will never change. What I'm trying to find out is can you have a text file that defines column information, rather than having to create a new sub routine with the different format. Basically it's a CSV reader, that reads through a file and places the columns of information into a format we require. Here is a test sample
currentrow = csvreader.ReadFields() account(0) = (currentrow(0)) 'Account number account(1) = (currentrow(29)) 'Card Number account(2) = (currentrow(4)) 'Firstname account(3) = (currentrow(6)) 'Last Name account(4) = (currentrow(2)) 'Title account(6) = (currentrow(15)) 'Gender account(7) = (currentrow(22)) 'Expirydate account(9) = (currentrow(14)) 'Birthdate account(12) = (currentrow(11)) 'Postcode account(15) = (currentrow(16)) 'phone number account(20) = (currentrow(20)) 'Email account(26) = (currentrow(7)) 'street account(27) = (currentrow(9)) 'suburb account(29) = (currentrow(10)) 'state account(40) = (currentrow(25)) 'accountgroup当前正在阅读的内容是什么。可以用从文本文件中读取的变量替换行号,并且可能有人指出我正确的方向如何执行此操作:) Iain Stewart
the currentrow is what's being read. Can the row numbers be replaced with a variable which is read from a text file, and could someone point me in the right direction on how to do this :) Iain Stewart
推荐答案如果我正确理解了这个问题,为什么不将映射信息存储在配置文件中并从那里读取。 基本上每个元素都有两条信息: - 元素的目标列号 - 元素的源列号 例如,名字将有2作为目标,4作为源 要使用配置文件你可以使用 ConfigurationManager.AppSettings [ ^ ]。 示例行看起来像 If I understand the question correctly, why not store the mapping information in a configuration file and read it from there. Basically you would have two pieces of information for each element: - target column number for an element - source column number for an element For example first name would have 2 as target and 4 as source To use a configuration file you can use ConfigurationManager.AppSettings [^]. The example line could look something like account(CInt(appSettings("FirstName_Target"))) = (currentrow(CInt(appSettings("FirstName_Source"))))
采用appSetting正确定义,如MSDN中的示例所示。
taken that the appSetting is defined properly as in the example in MSDN.
更多推荐
CSV文件和多种格式的可自定义程序
发布评论