| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 652 人关注过本帖
标题:文本数据导入到 Grid 中
只看楼主 加入收藏
hexiemoling
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-7-3
收藏
 问题点数:0 回复次数:0 
文本数据导入到 Grid 中

string str1;
string str2;
char[] str = new char[220];

char[] ColValue1 = new char[50];
char[] ColValue2 = new char[50];
char[] ColValue3 = new char[50];
char[] ColValue4 = new char[50];
char[] ColValue5 = new char[50];
char[] ColValue6 = new char[50];
char[] ColValue7 = new char[50];
char[] ColValue8 = new char[50];
char[] ColValue9 = new char[50];
char[] ColValue10 = new char[50];
char[] ColValue11 = new char[50];
char[] ColValue12 = new char[50];
char[] ColValue13 = new char[50];
char[] ColValue14 = new char[50];
char[] ColValue15 = new char[50];
char[] ColValue16 = new char[50];
char[] ColValue17 = new char[50];
char[] ColValue18 = new char[50];
char[] ColValue19 = new char[50];
char[] ColValue20 = new char[50];
char[] ColValue21 = new char[50];
char[] ColValue22 = new char[50];
char[] ColValue23 = new char[50];
char[] ColValue24 = new char[50];
char[] ColValue25 = new char[50];
char[] ColValue26 = new char[50];
char[] ColValue27 = new char[50];
char[] ColValue28 = new char[50];
char[] ColValue29 = new char[50];
char[] ColValue30 = new char[50];
char[] ColValue31 = new char[50];
char[] ColValue32 = new char[50];
char[] ColValue33 = new char[50];

int i=1;
int RowNo= this.efGrid1.Row;

//显示“打开画面”
if(openFileDialog1.ShowDialog() == DialogResult.Cancel)
return;

//读取文件
System.IO.StreamReader f_name = new System.IO.StreamReader(openFileDialog1.FileName, System.Text.Encoding.Default);

//读取标题行
str1 = f_name.ReadLine();
int x = 0;
for( x = 0; x < str1.Length; x ++ )
{
str[ x ] = str1[ x ];
}
str[ x++ ] = '\0';
str[ x++ ] = '\t';
str[ x ] = '\n';

for( x = 0; x < str1.Length; x ++ )
{
str[ x ] = ' ';
}
str[ x++ ] = '\0';
str[ x++ ] = '\t';
str[ x ] = '\n';

//读取数据行,并将标题行覆盖
while((str2 = f_name.ReadLine()) != null)
{
x = 0;
for( x = 0; x < str2.Length; x ++ )
{
str[ x ] = str2[ x ];
}
str[ x++ ] = '\0';
str[ x++ ] = '\t';
str[ x ] = '\n';

int ii = 0;
int j = 0;
while (str[ii] != '\t' && str[ii] != '\0' && str[ii] != '\n')
{
ColValue1[j++] = str[ii++];
}
ColValue1[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue2[j++] = str[ii++];
}
ColValue2[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue3[j++] = str[ii++];
}
ColValue3[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue4[j++] = str[ii++];
}
ColValue4[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue5[j++] = str[ii++];
}
ColValue5[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue6[j++] = str[ii++];
}
ColValue6[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue7[j++] = str[ii++];
}
ColValue7[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue8[j++] = str[ii++];
}
ColValue8[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0' && str[ii] != '\n')
{
ColValue9[j++] = str[ii++];
}
ColValue9[j] = '\0';


j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue10[j++] = str[ii++];
}
ColValue10[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue11[j++] = str[ii++];
}
ColValue11[j] = '\0';


j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue12[j++] = str[ii++];
}
ColValue12[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue13[j++] = str[ii++];
}
ColValue13[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue14[j++] = str[ii++];
}
ColValue14[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue15[j++] = str[ii++];
}
ColValue15[j] = '\0';

j = 0;
ii++;
while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
{
ColValue16[j++] = str[ii++];
}
ColValue16[j] = '\0';

// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue17[j++] = str[ii++];
// }
// ColValue17[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue18[j++] = str[ii++];
// }
// ColValue18[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue19[j++] = str[ii++];
// }
// ColValue19[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue20[j++] = str[ii++];
// }
// ColValue20[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue21[j++] = str[ii++];
// }
// ColValue21[j] = '\0';
//
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue22[j++] = str[ii++];
// }
// ColValue22[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue23[j++] = str[ii++];
// }
// ColValue23[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue24[j++] = str[ii++];
// }
// ColValue24[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue25[j++] = str[ii++];
// }
// ColValue25[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue26[j++] = str[ii++];
// }
// ColValue26[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue27[j++] = str[ii++];
// }
// ColValue27[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue28[j++] = str[ii++];
// }
// ColValue28[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue29[j++] = str[ii++];
// }
// ColValue29[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue30[j++] = str[ii++];
// }
// ColValue30[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue31[j++] = str[ii++];
// }
// ColValue31[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue32[j++] = str[ii++];
// }
// ColValue32[j] = '\0';
//
// j = 0;
// ii++;
// while (str[ii] != '\t' && str[ii] != '\0'&& str[ii] != '\n')
// {
// ColValue33[j++] = str[ii++];
// }
// ColValue33[j] = '\0';

efGrid1[i,"check_option"] = true;

efGrid1[i,"VOUCHER_DESC"] = charTostring(ColValue1);
efGrid1[i,"DEBIT_CREDIT"] = charTostring(ColValue2);
efGrid1[i,"ACCOUNT_TITLE_CODE"] = charTostring(ColValue3);
efGrid1[i,"ID_CODE_TYPE"] = charTostring(ColValue4);
efGrid1[i,"ID_CODE"] = charTostring(ColValue5);
efGrid1[i,"REFERENCE_CODE_TYPE"] = charTostring(ColValue6);
efGrid1[i,"REFERENCE_CODE"] = charTostring(ColValue7);
efGrid1[i,"CURRENCY_KIND"] = charTostring(ColValue8);
efGrid1[i,"RMB_AMT"] = charTostring(ColValue9);
efGrid1[i,"CRRN_RATE"] = charTostring(ColValue10);
efGrid1[i,"FOREIGN_AMT"] = charTostring(ColValue11);
efGrid1[i,"QUANTITY"] = charTostring(ColValue12);
efGrid1[i,"QUANTITY_UNIT"] = charTostring(ColValue13);
efGrid1[i,"AFFIX_COUNT"] = charTostring(ColValue14);

efGrid1[i,"ADDENDA_SIGN"] = charTostring(ColValue15);
efGrid1[i,"SYSTEM_ID"] = charTostring(ColValue16);
//
// efGrid1[i,"REC_CREATE_TIME"] = charTostring(ColValue17);
// efGrid1[i,"VOUCHER_NO"] = charTostring(ColValue18);
// efGrid1[i,"VOUCHER_DATE"] = charTostring(ColValue19);
// efGrid1[i,"VOUCHER_SEQ_NO"] = charTostring(ColValue20);
// efGrid1[i,"ACCOUNT_PERIOD_NO"] = charTostring(ColValue21);
//
// efGrid1[i,"VOUCHER_STATUS"] = charTostring(ColValue22);
// efGrid1[i,"VOUCHER_STATUS_DESC"] = charTostring(ColValue23);
// efGrid1[i,"VOUCHER_SUMMARY"] = charTostring(ColValue24);
// efGrid1[i,"VOUCHER_SUMMARY_DESC"] = charTostring(ColValue25);
// efGrid1[i,"VOUCHER_ASSORT"] = charTostring(ColValue26);
//
// efGrid1[i,"DEBIT_AMOUNT"] = charTostring(ColValue27);
// efGrid1[i,"DEBIT_QUANTITY"] = charTostring(ColValue28);
// efGrid1[i,"DEBIT_AMOUNT_FOREIGN"] = charTostring(ColValue29);
// efGrid1[i,"CREDIT_AMOUNT"] = charTostring(ColValue30);
// efGrid1[i,"CREDIT_QUANTITY"] = charTostring(ColValue31);
// efGrid1[i,"CREDIT_AMOUNT_FOREIGN"] = charTostring(ColValue32);
// efGrid1[i,"ACCOUNT_YEAR"] = charTostring(ColValue33);

i++;

this.efGrid1.EFUserRows++;

//设置列字段自动调节宽度
efGrid1.AutoSizeCols();


}
f_name.Close();


EF控件是我们自己做的,应用时需要自己修改下哦!!!

文本是以TAB键为分割符,文本文件的第一行必须顶格 我的测试数据如下:

凭证摘要 借贷 会计科目代码 户号代码 户号 参号代码 参号 币种 外币金额 人民币金额 汇率 数量 数量单位 附件张数 凭证类别 系统代号
采购发票入帐 1 2221010010 4 7% 1 10101010 1 0 70 1 6 KJZ CG
采购发票入帐 2 2202020 1 110411 1 0 800000 1 1000 6 KJZ CG
采购发票入帐 1 2221010010 4 17% 1 99887766 1 0 116239.32 1 6 KJZ CG

搜索更多相关主题的帖子: Grid 文本 数据 string char 
2007-07-03 22:32
快速回复:文本数据导入到 Grid 中
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017046 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved