使用c#或visual basic对.csv文件进行排序 [英] Sorting through a .csv file using c# or visual basic
问题描述
我没有c#或视觉基本经验,我正在寻找一些C#或可视化基本代码来排序csv文件并根据csv文件中的值编译txt文件,这可以使用控制台应用程序或任何东西来完成否则,只要它只是写txt文件并给出正确的输出。
输入文件(CSV文件)包含多个记录,每个记录有多个字段,分隔逗号
<前lang =text> 字段描述
账户持有人 - 帐户持有人的姓名和姓氏
accountnumber -Account number that需要借记
accounttype - 需要借记的账户类型
bankname -Bank账户持有
branch -Brach账户持有
金额 - 挂单需要借记兰德和分
日期 - 借记需要发生的日期(mm / dd / yyyy)
每个输出文件应该是银行ñ ame,它应该根据银行对csv中的行进行排序,并将它们输出到该银行的txt中,如果不存在则应该创建它。
每个文件顶部都有一行,一个标题记录,汇总了文件中的数据。标题记录将在一个长字符串中包含以下数据。
以下是Beep Bank的示例标题,其中100条记录的值为$ 90998.10。
BEEP BANK 1000009099810
元素说明Pad char Pad side长度
银行名称银行前16个字符名称[空格]右16
按文件名填写,如果名称小于
16字符长,则填充空格
。转换为
大写
记录计数文件中的数据记录数,0左3
描述为3个字符,
零左填充字符串
总值(以美分为单位)所有金额均为0左10
该文件,描述为10个字符,
零左填充字符串
总标题记录长度= 29
详细记录的构造如下。鉴于此,可以推断出每个细节记录的长度都是相同的。
以下是2012年12月31日从Maria Smith的信用卡扣除$ 100.72的示例详细记录卡,德班分行的账号123456.
MSmith,123456,CC,BankName,Durban,0010072,31201212;
元素描述Pad char Pad side长度
缩写帐户持有人的第一个首字母,描述为/ an / a 1
单个字符
姓氏姓氏(删除的空格)帐户持有人[空格]权利15
描述为15个字符,空格右边填充
字符串。所有空格要从姓氏中删除
,如填充之前的Le Roux。
AccountNr要借记的帐号,描述为14 [空格]权利14
字符,空格右边填充字符串
帐户类型帐户类型[空格]权利的助记符/缩写3
描述为3个字符,空格右边填充
字符串使用这些查找:
oCH =支票账户
oSAV =储蓄账户
oCR =信用卡
oOTH =任何其他账户类型
持有账户的分行分行名称,描述为[空格]权利10
a 10个字符,空格右边填充字符串
金额金额,以美分为单位,要从帐户中扣除,0左7
描述为7字符,零左填充字符串
日期借记日期描述为8字符串n / a不适用8
代表ddyyyymm格式的日期
总详细记录长度= 58
详细记录应排在文件头部下方。记录将根据金额按升序排序,然后根据帐户持有人的姓氏按升序排序。因此,如果找到两个相同金额的记录,则必须根据帐户持有人的姓氏对这些记录进行排序。
该文件应以CRLF结尾(运输最终记录后返回换行。
我还想尝试显示处理csv的进度,并给出用值生成的文件的摘要和计数
我将不胜感激任何输入
提前致谢
90998.10。
BEEP BANK 1000009099810
元素描述Pad char Pad side length
银行名称银行名称前16个字符[空格]右16
按文件名填写,填写空格
如果名称小于
16长字符。转换为
大写
记录计数文件中的数据记录数,0左3
描述为3个字符,
零左填充字符串
总值(以美分为单位)所有金额均为0左10
该文件,描述为10个字符,
零左填充字符串
总标题记录长度= 29
详细记录的构造如下。鉴于此,可以推断出每个细节记录的长度都相同。
这是一个要扣除的示例详细记录
< blockquote> 100.72于2012年12月31日,来自Maria Smith的信用卡,账号为123456,为德班分行。
MSmith,123456,CC,BankName,Durban,0010072, 31201212;
元素描述Pad char Pad side长度
缩写帐户持有人的第一个首字母,描述为/ an / a 1
单个字符
姓氏姓氏(删除的空格)帐户持有人[空格]权利15
描述为15个字符,空格右边填充
字符串。所有空格要从姓氏中删除
,如填充之前的Le Roux。
AccountNr要借记的帐号,描述为14 [空格]权利14
字符,空格右边填充字符串
帐户类型帐户类型[空格]权利的助记符/缩写3
描述为3个字符,空格右边填充
字符串使用这些查找:
oCH =支票账户
oSAV =储蓄账户
oCR =信用卡
oOTH =任何其他账户类型
持有账户的分行分行名称,描述为[空格]权利10
a 10个字符,空格右边填充字符串
金额金额,以美分为单位,要从帐户中扣除,0左7
描述为7字符,零左填充字符串
日期借记日期描述为8字符串n / a不适用8
代表ddyyyymm格式的日期
总详细记录长度= 58
详细记录应排在文件头部下方。记录将根据金额按升序排序,然后根据帐户持有人的姓氏按升序排序。因此,如果找到两个相同金额的记录,则必须根据帐户持有人的姓氏对这些记录进行排序。
该文件应以CRLF结尾(运输最终记录后返回换行。
我还想尝试显示处理csv的进度,并给出用值生成的文件的摘要和计数
我将不胜感激任何输入
提前致谢
< blockquote>你好会员,
如何使用 FileHelpers [ ^ ]库读取CSV文件。然后,您可以将此数据转储到任何数据库,并使用所需的排序顺序查询数据库,并使用FileHelpers再次输出文件。
问候,
I have no c# or visual basic experience and I am looking for some C# or visual basic code to sort through a csv file and compiles txt files depending on values in the csv file, this can be done using a console app or anything else, as long as it just writes the txt files and gives the correct output.
The input file (CSV File) contains multiple records, each with multiple fields, delimited by commas
Field Description
accountholder -First name and Surname of the account holder
accountnumber -Account number that needs to be debited
accounttype -Type of account that needs to be debited
bankname -Bank where the account is held
branch -Brach where the account is held
amount -Amount that needs to be debited, in rand and cent
date -Date that debit needs to happen (mm/dd/yyyy)
Each output file should be the bank name, it should sort the rows in the csv according to the bank and output them into the txt for that bank, if one does not exist it should create it.
Every file will have a single line at the top, a header record, summarizing the data in the file. The header record will have the following data in one long string.
Below is an example header for Beep Bank with 100 records to the value of $90998.10.
BEEP BANK 1000009099810
Element Description Pad char Pad side Length
Bank name First 16 characters of the Bank name [space] right 16
as per file name, padded with spaces
at the end if the name is less than
16 characters long. Convert to
Uppercase
Record count Number of data records in the file, 0 left 3
depicted as a 3 character,
zero-left padded string
Total value Value (in cents) of all amounts in 0 left 10
the file, depicted as a 10 character,
zero-left-padded string
Total Header Record Length = 29
The detail records will be constructed as below. Given this, it can be deduced that every detail record will be the same length.
Here is an example detail record to deduct $100.72 on 31 December 2012 from Maria Smith’s Credit Card, account number 123456 for the branch in Durban.
MSmith, 123456,CC, BankName,Durban,0010072,31201212;
Element Description Pad char Pad side Length
Initials First initial of account holder, depicted as a n/a n/a 1
single character
Surname Surname (spaces removed) of the account holder [space] right 15
depicted as a 15 character, space-right-padded
string.All spaces to be removed from surnames
like "Le Roux" before padding.
AccountNr Account number to be debited, depicted as a 14 [space] right 14
character, space-right-padded string
Account Type A mnemonic/abbreviation for the account type [space] right 3
depicted as a 3 character, space-right padded
string using these lookups:
oCH = Cheque account
oSAV = Savings account
oCR = Credit card
oOTH = Any other account type
Branch Branch name where account is held, depicted as [space] right 10
a 10 character, space-right-padded string
Amount Amount, in cents, to be deducted from account, 0 left 7
depicted as a 7 character, zero-left-padded string
Date Debit date depicted as a 8 character string n/a n/a 8
representing the date in the format ddyyyymm
Total Detail Record Length = 58
Detail records shall be sorted below the header in the file. Records are to be sorted in ascending order based on the amount, and then in ascending order based on the Account Holder’s surname. So where two records of the same amount is found, these records must be sorted based on the surname of the account holder.
The file should end with a CRLF (Carriage return line feed) after the final record.
I would also like to try and show the progress of processing the csv and give a summary of the files produced with values and counts
I will appreciate any input
Thanks in advance
90998.10.
BEEP BANK 1000009099810 Element Description Pad char Pad side Length Bank name First 16 characters of the Bank name [space] right 16 as per file name, padded with spaces at the end if the name is less than 16 characters long. Convert to Uppercase Record count Number of data records in the file, 0 left 3 depicted as a 3 character, zero-left padded string Total value Value (in cents) of all amounts in 0 left 10 the file, depicted as a 10 character, zero-left-padded string Total Header Record Length = 29
The detail records will be constructed as below. Given this, it can be deduced that every detail record will be the same length.
Here is an example detail record to deduct
100.72 on 31 December 2012 from Maria Smith’s Credit Card, account number 123456 for the branch in Durban.
MSmith, 123456,CC, BankName,Durban,0010072,31201212; Element Description Pad char Pad side Length Initials First initial of account holder, depicted as a n/a n/a 1 single character Surname Surname (spaces removed) of the account holder [space] right 15 depicted as a 15 character, space-right-padded string.All spaces to be removed from surnames like "Le Roux" before padding. AccountNr Account number to be debited, depicted as a 14 [space] right 14 character, space-right-padded string Account Type A mnemonic/abbreviation for the account type [space] right 3 depicted as a 3 character, space-right padded string using these lookups: oCH = Cheque account oSAV = Savings account oCR = Credit card oOTH = Any other account type Branch Branch name where account is held, depicted as [space] right 10 a 10 character, space-right-padded string Amount Amount, in cents, to be deducted from account, 0 left 7 depicted as a 7 character, zero-left-padded string Date Debit date depicted as a 8 character string n/a n/a 8 representing the date in the format ddyyyymm Total Detail Record Length = 58
Detail records shall be sorted below the header in the file. Records are to be sorted in ascending order based on the amount, and then in ascending order based on the Account Holder’s surname. So where two records of the same amount is found, these records must be sorted based on the surname of the account holder.
The file should end with a CRLF (Carriage return line feed) after the final record.
I would also like to try and show the progress of processing the csv and give a summary of the files produced with values and counts
I will appreciate any input
Thanks in advance
Hello Member,
How about using FileHelpers[^] Library to read the CSV file. You can then dump this data to any database and query the database with desired sort order and ouput a file again using FileHelpers.
Regards,
这篇关于使用c#或visual basic对.csv文件进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!