将 CSV 导入到用户定义的类结构中
我有一个联系人管理器程序,我想提供导入 csv 文件的功能。问题在于不同的数据源以不同的方式对字段进行排序。我想到为用户编写一个接口来告诉它字段顺序以及如何处理异常。
以下是许多可能的字段顺序之一的示例行: "ID#","姓名","排名","地址1","地址2","城市","州","国家","邮政编码","电话#","电子邮件","加入日期" ,"赞助商 ID","赞助商名称" “Z1234”、“致电安森”、“STU”、“1234 E.6578 S.”、“”、“Somecity”、“TX”、“美国”、“012345”、“000-000-0000” ,"[电子邮件受保护]","2010/5/24", "z12343","Quantum Independence"
请注意,在一个数据字段“Name”中,有一个逗号分隔姓氏和名字,而在另一个数据字段中则没有。
我的计划是为每个字段(即 ID、姓名、城市等)设置一行,并添加一个“导入到”声明和包含以下选项的列表框:不导入、业务>加入日期、名字、邮政编码 并且程序将它们识别为对象的属性...
我还希望用户能够记录预设的字段顺序,以便他们可以将它们重新用于来自同一下载源的 csv 文件。
然后我还需要它检查是否存在一条记录全部准备好(是否有 Anson Call 全部准备好记录?)并允许用户告诉它如果有记录该怎么办(即邮寄地址可能有变化,所以如果该字段已填写,请覆盖它,或者此邮寄地址无效,请保留此人的当前数据不变,覆盖其余部分)。
虽然我有能力编写这个...我对此不是很兴奋,我想知道是否有一个或一组工具可以准备好执行大部分功能...
我希望这是有道理的...
I have a contact manager program and I would like to offer the feature to import csv files. The problem is that different data sources order the fields in different ways. I thought of programming an interface for the user to tell it the field order and how to handle exceptions.
Here is an example line in one of many possible field orders:
"ID#","Name","Rank","Address1","Address2","City","State","Country","Zip","Phone#","Email","Join Date","Sponsor ID","Sponsor Name"
"Z1234","Call, Anson","STU","1234 E. 6578 S.","","Somecity","TX","United States","012345","000-000-0000","[email protected]","5/24/2010","z12343","Quantum Independence"
Notice that in one data field "Name" there is a comma to separate last name and first name and in another there is not.
My plan is to have a line for each field (ie ID, Name, City etc.) and a statement "import to" and list box with options like: Don't Import, Business>Join Date, First Name, Zip
and the program recognizes those as properties of an object...
I'd also like the user to be able to record preset field orders so they can re-use them for csv files from the same download source.
Then I also need it to check if a record all ready exists (is there a record for Anson Call all ready?) and allow the user to tell it what to do if there is a record (ie mailing address may have changes, so if that field is filled overwrite it, or this mailing address is invalid, leave the current data untouched for this person, overwrite the rest).
While I'm capable of coding this...i'm not very excited about it and I'm wondering if there's a tool or set of tools out there to all ready perform most of this functionality...
I hope this makes sense...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有标题行吗?
通常在 CSV 文件中,第一行是标题。
如果是这样,您可以使用标题行来确定顺序,只需一个列名称列表,并且仅在列名称不匹配时提示用户。(然后可以将其自动添加到预定义列表中)。
编辑:
即使标头不存在,添加一个标头也很简单。该文件可以手动编辑。或者在您的程序中让用户定义它(从您的预定义列表中)
Is there a header row?
usually in CSV files, the first line is the header.
If so you could use the header line to determine the order, just have a list of column names, and only prompt the user if a column name does not match.(this could then be auto added into the predefined list).
EDIT:
even if a header does not exist, its simple enough to add one. The file can be manually edited. Alternatively in your program let the user define it (from your predefined list)
我找不到任何准备好的工具,也没有人回复过,所以为了让问题得到解答,直到另行通知,答案是:否。
I can't find any tools all ready out there and no one has replied otherwise, so for the sake of leaving a question answered until otherwise notified the answer is: no.