Converter (TSV to Excel-CSV) SJIS

Converter: TSV to Excel-CSV (SJIS)
A tab delimited text (TSV) stored in a String type data item is saved as an Excel compatible CSV file in a File-type Data Item.
2018 © Questetra, Inc. (MIT License)
Configs
  • A: Select STRING DATA for TSV Data *
  • B: Set COL IDs for Extraction (e.g. “0,1,5,3,6”) *
  • C: Select STRING DATA for File Name *
  • D: Select FILES DATA (append) *
Script
//////// START "main()" ////////
main();
function main(){

//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA   = configs.get( "conf_DataIdA" ) + "";
const dataIdC   = configs.get( "conf_DataIdC" ) + "";
const dataIdD   = configs.get( "conf_DataIdD" ) + "";
const colIds    = configs.get( "conf_ColIds" )  + "";
const arrColIds = colIds.split(",");
// 'java.lang.String' (String Obj) to javascript primitive 'string'
// https://wiki.openjdk.java.net/display/Nashorn/Rhino+Migration+Guide#RhinoMigrationGuide-JavaScriptvsJavaStrings
// https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/api.html#sthref21


//// == Data Retrieving / ワークフローデータの参照 ==
let   myTsv     = engine.findDataByNumber( dataIdA );
if(   myTsv   !== null ){ myTsv += ""; }else{
  throw new Error( "Source TSV data is NULL" );
}
const arrMyTsv  = myTsv.split("\n");

let   fileName  = engine.findDataByNumber( dataIdC ) + ""; // NULL to "null"
let   myFiles   = engine.findDataByNumber( dataIdD ); // java.util.ArrayList
if( myFiles === null ){ myFiles = new java.util.ArrayList(); }


//// == Calculating / 演算 ==
let   newTsv    = "";
for( let i = 0; i < arrMyTsv.length; i++){
  let arrCellValues = arrMyTsv[i].split("\t");
  for( let j = 0; j < arrColIds.length; j++ ){
    newTsv += arrCellValues[ parseInt( arrColIds[j] ) ];
    if( j != arrColIds.length - 1 ){
      newTsv += "\t";
    }
  }
  if( i != arrMyTsv.length -1 ){
    newTsv += "\n";
  }
}

// for sjis-csv
let newSjisCsv = newTsv.replace( /,/g, "" ).replace( /\t/g, "," );

myFiles.add(
  new com.questetra.bpms.core.event.scripttask.NewQfile(
    fileName,
//    "text/tab-separated-values; charset=x-UTF-16LE-BOM",
    "text/comma-separated-values; charset=Shift_JIS", // for sjis
//    newTsv
    newSjisCsv
  )
);


//// == Data Updating / ワークフローデータへの代入 ==
engine.setDataByNumber( dataIdD, myFiles );

} //////// END "main()" ////////

Download

Capture

Notes

  • It is also capable of changing the order of columns, filtering, listing duplicately.
  • The file entity consists of comma-separated-values (Shift-JIS)
  • Compare to tab-separated-values (utf-16le-bom) version, the availability of smartphone display and data import increases, but comma information in data misses.

See also

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top