TSV 文字列; 全行に固定値を追加 (TSV String; Add Static Value to All Lines)

全行の末尾にセルを1つ追加します。なお、TSV末尾や先頭の空白文字や改行文字は予め削除されます。また、各行のTabセパレータの数が不一致の場合はセル追加することなくエラー終了します。

2019-07-20 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/tsv-string-add-static-value-to-all-lines/

Configs
  • A: TSVデータが格納されている文字列型データ項目を選択してください *
  • B: 追加される文字列をセットしてください (例 “課税売上10%”) #{EL}
  • C: 生成TSVが格納される文字列型データ項目を選択してください(更新) *
Script
// (c) 2019, Questetra, Inc. (the MIT License)


//////// START "main()" ////////
main();
function main(){ 


//// == Config Retrieving / 工程コンフィグの参照 ==
const dataIdA = configs.get( "conf_DataIdA" ) + ""; // config required
const cellStr = configs.get( "conf_CellStr" ) + "";
const dataIdC = configs.get( "conf_DataIdC" ) + ""; // config required
if( cellStr === "" ){
  engine.log( " AutomatedTask StringWarning:" +
              " CellStr is empty" );
}

//// == Data Retrieving / ワークフローデータの参照 ==
if( engine.findDataByNumber( dataIdA ) === null ){
  throw new Error( "\n AutomatedTask UnexpectedStringError:" +
                   " String {A} is null \n" );
}
const inputTsv = (engine.findDataByNumber( dataIdA ) + "").trim();
if( inputTsv == "" ){
  throw new Error( "\n AutomatedTask UnexpectedStringError:" +
                   " String {A} is empty \n" );
}


//// == Calculating / 演算 ==
let   outputTsv = "";
const arrInputTsv = inputTsv.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " String {A} as TSV, number of lines " + arrInputTsv.length );
const arrHeaderCells = arrInputTsv[0].split("\t");
engine.log( " AutomatedTask SinglelineString:" + 
            " TSV Header, number of cells " + arrHeaderCells.length );

for (let i=0; i < arrInputTsv.length; i++){
  const arrCells = arrInputTsv[i].split("\t");
  if( arrCells.length !== arrHeaderCells.length ){
    throw new Error( "\n AutomatedTask UnexpectedStringError:" + 
      " String {A} as TSV, number of delimiters in each row must be same: Row " + i + "\n");
  }
  outputTsv += arrInputTsv[i] + "\t" + cellStr;
  if( i !== arrInputTsv.length - 1 ){
    outputTsv += "\n";
  }
}


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


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

Download

Capture

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

%d