Converter (TSV to Excel-CSV FILE)
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.
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 FILE DATA (append) *
Script (click to open)
// GraalJS Script (engine type: 2)
// (c) 2021, Questetra, Inc. (the MIT License)

//////// 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'


//// == 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";
  }
}

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


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

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

Download

2021-07-06 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/addons/converter-tsvtoexcelcsv-2021/
The Add-on import feature is available with Professional edition.

Notes

  • It is also capable of changing the order of columns, filtering, listing duplicately.
  • The file entity consists of tab-separated-values (utf-16le-bom)

Capture

See also

1 thought on “Converter (TSV to Excel-CSV FILE)”

  1. Pingback: Converter (TSV to Excel-CSV File) – Questetra Support

Comments are closed.

%d bloggers like this: