各位,如何将以下文本文件的内容导入EXCEL或DBF等数据库表中:
这个文本文件是航天防伪开票系统中导出的,这系统只能导成这种格式。但我需要将他导入K3系统中。请各位高人帮帮忙,给点思路,最好写一段出来,小弟先谢了。数据库中关键字段被加了密的,所以没不考虑直接操作数据库的方式。
*****invout.txt********SJJK0201~~已开发票传出
2~~20060123~~20060123
//发票1
0~~0~~0~~1100012140~~928238~~6~~20060123~~01~~~~916517.35~~0.17~~155807.94~~钢铁公司~~111024727447400~~连界~~县工行~~贸易公司~~110101000000000~~经济技术开发区~~中国农业银行~~~~郑蕾~~~~
0~~铝镁尖晶石浇注料~~~~吨~~42.18~~73905.13~~0.17~~12563.87~~2050.00~~1~~1009
0~~铝镁铬浇注料~~~~吨~~22.5~~49278.85~~0.17~~8377.40~~2562.50~~1~~1009
0~~氧化镁球~~~~吨~~1084.52~~725110.59~~0.17~~123268.80~~782.26~~1~~1009
0~~烧结点火炉吊挂梁预制件~~~~吨~~6.28~~17605.47~~0.17~~2992.93~~3280.00~~1~~1009
0~~锚固砖~~~~台~~1.34~~3416.15~~0.17~~580.74~~2982.75~~1~~1405
0~~环烧点火车浇注料~~~~吨~~18.08~~47201.16~~0.17~~8024.20~~3054.50~~1~~1009
//发票2
0~~0~~0~~1100012140~~928239~~7~~20060123~~01~~~~939364.30~~0.17~~159691.95~~钢铁公司~~111024727447400~~连界~~县工行~~贸易公司~~110101000000000~~经济技术开发区~~中国农业银行~~~~郑蕾~~~~
0~~安全层镁铬砖~~~~吨~~30~~123525.64~~0.17~~20999.36~~4817.50~~1~~1009
0~~T、Z硅酸铝纤维毡~~~~吨~~1~~3504.27~~0.17~~595.73~~4100.00~~1~~1109
0~~H、T、D捣打料~~~~吨~~40~~108632.48~~0.17~~18467.52~~3177.50~~1~~1109
0~~H、T、C浇注料~~~~吨~~15~~89358.97~~0.17~~15191.03~~6970.00~~1~~1109
0~~H、T、B浇注料~~~~吨~~100~~499358.97~~0.17~~84891.03~~5842.50~~1~~1109
0~~H、T、A浇注料~~~~吨~~40~~101623.93~~0.17~~17276.07~~2972.50~~1~~1109
0~~95砂细粉~~~~吨~~6.1~~13360.04~~0.17~~2271.21~~2562.50~~1~~1009*****invout.txt********有以下字段内容:
1100012140:类别代码
928238,928239:发票号码
6,7:商品条数
20060123:开票日期
01:月份
916517.35,939364.30:金额合计
155807.94,159691.95:税额合计
钢铁公司:购方名称
111024727447400:购方税号
连界:购方地址
县工行:购方开户行
贸易公司:销方名称
110101000000000:销方税号
经济技术开发区:销方地址
中国农业银行:销方开户行
郑蕾:开票人
铝镁尖晶石浇注料,铝镁铬浇注料,氧化镁球等:商品名称
吨:计量单位
~~42.18~~73905.13~~0.17~~12563.87~~2050.00~~1~~1009:依次是:数量,金额,税率,税额,单价,打印标志,商品税目一张发票有多条商品信息,需形成多条记录。每条记录前三个0以及商品名称前一字段0可给任意字段意义。商品信息与共用信息间有回车符,每条商品信息间也有回车符。

解决方案 »

  1.   

    手工整理一下這個txt文件﹐至少的整理的一列一列的鮮明﹐然后可以導入到access中(在access中把TXT匯入資料﹐有一中手工划線分割列的方式)﹐導入后﹐資料就成為規范的表了﹐然后又可以從access匯出為excel 。
      

  2.   

    我准备写一段程序来实现自动生成EXCEL或DBF。楼上老兄的方法不太适用。不过还是谢谢:-)
      

  3.   

    子从表,下面的代码没完整的处理,只读了主表的数据,从表处理方法一样,就是一个循环。结构里好象不对,~~0.17~~是什么,没说明,数据对不齐。function FindNextTokenStr(strSource:string):string;
    var
        iBegin,iEnd,i:integer;
    begin
        iBegin:=-1;
        iEnd:=Length(strSource)+1;
        for i:=1 to Length(strSource) do
        begin
            if (iBegin<0) and (strSource[i]<>'~') then
                iBegin:=i;        if iBegin>=0 then
                if strSource[i]='~' then
                begin
                    iEnd:=i;
                    break;
                end;
        end;
        Result:=Copy(strSource,iBegin,iEnd-iBegin);
    end;function CopyTokenStr(strToken:string;strSource:string):string;
    var
        iBegin:integer;
    begin
        iBegin:=Pos(strToken,strSource);
        Result:=Copy(strSource,iBegin+Length(strToken),Length(strSource));
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
        i:integer;
        strLine,strTemp,strValue:string;
    begin
        Memo2.Clear;
        strValue:='"类别代码","发票号码","商品条数","开票日期","月份","金额合计","税额合计","购方名称","购方税号","购方地址","购方开户行","销方名称","销方税号","销方地址","销方开户行","开票人"';
        Memo2.Lines.Add(strVAlue);
        for i:=0 to Memo1.Lines.Count-1 do
        begin
            strValue:='';
            strLine:=Memo1.Lines[i];        if(Pos('0~~0~~0',strLine)=0)then//这里只读了0~~0~~0开头的行,就是主表的数据,以0~~开头的是从表,这里没处理。
                continue;
                
            strLine:=CopyTokenStr('0~~0~~0',strLine);
            strTemp:=FindNextTokenStr(strLine);//类别代码
            strLine:=CopyTokenStr(strTemp,strLine);
            strValue:='"'+strTemp;        strTemp:=FindNextTokenStr(strLine);//发票号码
            strLine:=CopyTokenStr(strTemp,strLine);
            strValue:=strValue+'","'+strTemp;        strTemp:=FindNextTokenStr(strLine);//商品条数
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//开票日期
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//月份
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//金额合计
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//税额合计
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//购方名称
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//购方税号
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//购方地址
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//购方开户行
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//销方名称
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//销方税号
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//销方地址
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//销方开户行
            strValue:=strValue+'","'+strTemp;
            strLine:=CopyTokenStr(strTemp,strLine);        strTemp:=FindNextTokenStr(strLine);//开票人
            strValue:=strValue+'","'+strTemp+'"';        Memo2.Lines.Add(strValue);
        end;
        Memo2.Lines.SaveToFile('e:\a.csv');//存储为csv的excel表,可以用excel打开。
    end;
      

  4.   

    下回让那些导出的数据以XML导出,别来这些没用的