Talend tools to organize files and output files to Excel

Source: Internet
Author: User
Tags first string

Problem Description:

Every day, a certain TXT file is generated, the TXT file contains a number of personal information, each of the personal information is extracted and then placed in the Excel file list.

Solution Ideas:

The information in the 1.txt file contains multiple pieces, each of which generates a temporary file.

2. Read the temporary files and put them in the Excel list.

3. In view of the two executions, delete the temporary files and the previous data.

Talend specific processes such as:

Explanatory notes:

① in order to be able to execute the second time, so here first delete temporary files inside the Temp folder

The code is as follows:

When "コンポーネント"で, コードを books きます
パラメータ"context.datasourcepath"がcontxtで, setting able,
Outputdataconver.filedel (Context.datasourcepath










}

② The purpose here is to put the "tjava3" code to the end of execution and then execute it down.

Generated by " tjava5"?" Right キーを Joab し"?" トリガー"?" サブジョブがokの "

③④⑤ in order to implement the second execution, the first execution of the data to delete the function, again to retrieve, the current data file there is no data of the day

The ③ is generated in the form of " メタデータ"?" excelファイル"?" Right キーを Joab し"?" excelファイル made into する"

④ just matches the data on both ends.

⑤ to determine if the data was executed once, that is, whether the data of the day contains

The day のデータがあれば, パラメータが "flase" set する//パラメータ"context.datadelfg "が contxt で, set able, initial が "true" occupies set するif (( New SimpleDateFormat ("YyyyMMdd"). Format (new Date ())). Equals (Input_row. O) {    CONTEXT.DATADELFG = "false";    }

⑥ a temporary control, in order to facilitate the addition of judgment conditions. Add a mouse selection in the control "tjava5"?" Right キーを Joab し"?" トリガー"?" Conditional pay Bootcut Natsumi Sato Line "

if (order:1) The judging condition ("false". Equals (CONTEXT.DATADELFG))

The IF (order:2) condition ("true". Equals (CONTEXT.DATADELFG))


⑦⑧⑨ here is to implement, delete the day's data to generate temporary files

The setting of the ⑧ is as follows


The implementation of the ⑩ uses the temporary generated file to overwrite the target file, i.e. copy
Use pre-prepared templates to restore temporarily generated temporary files to their original state

? generate multiple personal information inside a single TXT file into, a file in a personal message

キーワード: First string keyfilename =context.datasourcepath + "the name of. txt"; list<string> keyfilenamelist = Outputdataconver.getkeyword (keyfilename);//キーワード: Sex String keyFileSex = Context.datasourcepath + "sex. txt"; list<string> keyfilesexlist = Outputdataconver.getkeyword (keyfilesex);//キーワード: Year ginkgo String KeyFileAge = Context.datasourcepath + "year ginkgo. txt"; list<string> keyfileagelist = Outputdataconver.getkeyword (keyfileage)//キーワード: Finance Economics Fukuoka number of years String keyFileExperience= Context.datasourcepath + "Finance economics Fukuoka. txt"; list<string> keyfileexperiencelist = Outputdataconver.getkeyword (keyfileexperience);//キーワード: The most-sent station String Keyfilestation = Context.datasourcepath + "most station"; list<string> keyfilestationlist = Outputdataconver.getkeyword (keyfilestation);//キーワード: Japanese レベルstring Keyfilelevel = Context.datasourcepath + "Japanese language レベル.txt"; list<string> keyfilelevellist = Outputdataconver.getkeyword (keyfilelevel);//キーワード:スキルstring KeyFileSkill = Context.datasourcepath + "スキル.txt"; List<string> Keyfileskilllist = Outputdataconver.getkeyword (Keyfileskill);//キーワード: industrial String keyfileindustry = Context.datasourcepath + "industrial. txt"; list<string> keyfileindustrylist = Outputdataconver.getkeyword (keyfileindustry);//キーワード: Want single Assessment String Keyfileprice = Context.datasourcepath + "Hope single assessment. txt"; list<string> keyfilepricelist = Outputdataconver.getkeyword (Keyfileprice);//Specify のパス under のファイル get String path = Context.datasourcepath + (New SimpleDateFormat ("YyyyMMdd"). Format (new Date ())) + "\ \"; list<string> filenamelist = outputdataconver.traversefolder (path); for (string fi:filenamelist) {string name =    Fi.replace (Path, "");    File File = new file (FI);  FileWriter Writer=null;    Try (InputStreamReader fr = new InputStreamReader (new FileInputStream (file), "SJIS");    BufferedReader reader = new BufferedReader (FR)) {String temp = ""; String kkcy1 = Context.datasourcepath + "temp/" + name.substring (0,name.length ()-4); String kkcy2= name.substring (Name.length () -4, Name.length ()); int index = 0;boolean flag= True;boolean Sexflag = True;boolean Ageflag = true;//txtファイル content reading cups take りwhile ((temp = Reader.readline ())! = null) {String NAMESTR = Outputdataconver.keyword (temp, keyfilenamelist), if (! "". Equals (NAMESTR)) {if (!flag) {writer.close (); flag = true;}   File FileText = new file (Kkcy1 + "_" + Index + kkcy2);         Writer=new FileWriter (FileText); index = index + 1; Writer.write ("Pre-Name:" + Namestr.trim ()), Writer.write ("\ r \ n"), Writer.write ("club:" + name), Writer.write ("\ r \ n"); Sexflag = False;ageflag = False;flag = false; }if (!sexflag) {String SEXSTRHS = outputdataconver.keywordsex (temp); if (!sexstrhs.equals (")") {Sexflag = true; Writer.write ("Sex:" + Sexstrhs.trim ()), Writer.write ("\ r \ n");}} String sexstr = Outputdataconver.keyword (temp, keyfilesexlist), if (! "". Equals (Sexstr)) {writer.write ("Sex:" + Sexstr.trim ()); Writer.write ("\ r \ n");} if (!ageflag) {String AGESTRHS = outputdataconver.keywordage (temp); if (!agestrhs.equals (")") {Ageflag = true; Writer.write ("Year Ginkgo:" + Agestrhs.trim ()) writer.write ("\ r \ n");}} String agestr = Outputdataconver.keyword (temp, keyfileagelist), if (! "". Equals (Agestr)) {Writer.write ("Year Ginkgo:" + Agestr.trim ()); Writer.write ("\ r \ n");} String experiencestr = Outputdataconver.keyword (temp, keyfileexperiencelist), if (! "". Equals (Experiencestr)) {writer.write ("Finance Economics Fukuoka Years:" + Experiencestr.trim ()); Writer.write ("\ r \ n");} String stationstr =outputdataconver. KeyWord (temp, keyfilestationlist), if (! "". Equals (Stationstr)) {writer.write ("Nearest station:" + Stationstr.trim ()); Writer.write ("\ r \ n");} String levelstr = Outputdataconver.keyword (temp, keyfilelevellist), if (! "". Equals (Levelstr)) {writer.write ("Japanese レベル:" + Levelstr.trim ()); Writer.write ("\ r \ n");} String skillstr = Outputdataconver.keyword (temp, keyfileskilllist), if (! "". Equals (Skillstr)) {Writer.write ("スキル:" + Skillstr.trim (). Replace (",", ",")); Writer.write ("\ r \ n");} String industrystr = Outputdataconver.keyword (temp, keyfileindustrylist), if (! "". Equals (Industrystr)) {writer.write ("Industry:" + Industrystr.trim ()); Writer.write ("\ r \ n");} String pricestr = OutputdatacOnver.keyword (temp, keyfilepricelist), if (! "". Equals (Pricestr)) {Writer.write ("Wish Single Assessment:" + Pricestr.trim ()); Writer.write ("\ r \ n");}}  catch (FileNotFoundException e) {throw new Exception (e);              }finally{if (writer! = null) {Writer.close ();}          }}

???? Implement to write the personal information of each file into Excel

? 's settings

? The code

  String fileName = Context.datasourcepath + "temp/" + ((String) globalmap.get ("Tfilelist_1_current_file"));  File File = new file (fileName);    Try (InputStreamReader fr = new InputStreamReader (new FileInputStream (file), "SJIS");        BufferedReader reader = new BufferedReader (FR)) {String temp = "";            String[] strtemp= {",", ",", ",", ",", ",", ",", ",", ",", ",", ",", ",";    while ((temp = reader.readline ()) = null) {System.out.print ("Excel:" +temp);    if (Temp.indexof ("First Name:") >= 0) {strtemp[0] = temp.replace ("First Name:", "") + ",";    } if (Temp.indexof ("Sex:") >= 0) {strtemp[1] = Temp.replace ("Sex:", "") + ",";    if (Temp.indexof ("Year Ginkgo:") >= 0) {strtemp[2] = Temp.replace ("Year Ginkgo:", "") + ",";    if (Temp.indexof ("Finance Economics Fukuoka Years:") >= 0) {strtemp[3] = Temp.replace ("Finance Economics Fukuoka Years:", "") + ",";    if (Temp.indexof ("Most station:") >= 0) {strtemp[4] = Temp.replace ("Most Station:", "") + ","; } if (Temp.indexof ("Japanese レベル:") >= 0) {strtemp[5] = Temp.replace ("Japanese レベル:", "") + ",";    } if (Temp.indexof ("スキル:") >= 0) {strtemp[6] =temp.replace ("スキル:", "") + ",";    } if (Temp.indexof ("Industry:") >= 0) {strtemp[7] = temp.replace ("Industry:", "") + ",";    if (Temp.indexof ("Want Single Assessment:") >= 0) {strtemp[8] = Temp.replace ("Want Single Assessment:", "") + ",";    if (Temp.indexof ("Club:") >= 0) {strtemp[9] = Temp.replace ("Club:", "") + ",";    }} StringBuilder Strbudata = new StringBuilder ();        for (int i = 0; i < strtemp.length; i++) {strbudata.append (strtemp[i]);    } context.txtstr = Strbudata.tostring ();     Row1.txtstr = Context.txtstr;  } catch (FileNotFoundException e) {throw new Exception (e); }

? 's settings

Setting of constants

Talend tools to organize files and output files to Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.