コンバータ: TSV文字列 to テーブル

コンバータ: TSV文字列 to テーブル
コンバータ: TSV文字列 to テーブル (Converter: TSV-String to Table)

TSV文字列をテーブル型データに変換します。TSV文字列内の全てのセルの文字列値がテーブル型データ項目Bに上書きコピーされます。テーブルのカラム設計に不整合がある場合、エラーとなる場合があります。

2020-02-27 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/converter-tsv-string-to-table/

Configs
  • A: TSV文字列をセットしてください * #{EL}
  • B: テーブル型データを選択してください(更新)
  • B2: テーブル型データを選択してください(追記)
Script
// Nashorn Script (engine type: 1)
// 
// Notes:
// Copies text information of all cell values.
// Copies in the display order of the column. (Does not depend on column ID)
// If the number of columns decreases, the right columns will not be copied.
// If the number of columns increases, blank strings will be completed.
// For Numeric-column, the period "." is recognized as a decimal point.
// For Numeric-column, the comma "," is recognized as a thousand separator.
// For Select-column, the value must be choice ID. (Otherwise, not copied)
// Auto-calculated columns are reevaluated. (Not always the same value)
// To add data without erasing already stored cell data, use B2.
//
// Notes (ja):
// 全てのセル値の文字情報をコピーします。
// カラムの表示順にコピーします。(カラムIDに依らない)
// カラム列数が少なくなる場合は、右列部がカットされます。
// カラム列数が増える場合は、空白文字列で補完されます。
// 数値カラムへの値コピーは、ピリオド "." を小数点として認識して代入します。
// 数値カラムへの値コピーは、桁区切り文字 "," が存在しても構いません。
// 選択カラムへの値コピーは、選択肢IDでなければなりません。(コピーされません)
// 自動計算カラムは、再評価されます。(必ずしも同じ値になりません)
// 既に格納されているセルデータを消さずに追記したい場合は、B2をご利用ください。


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

//// == Config Retrieving / 工程コンフィグの参照 ==
const strTsv   = configs.get( "conf_StrTsv" )   + ""; // required
const dataIdB  = configs.get( "conf_DataIdB" )  + ""; // not required
const dataIdB2 = configs.get( "conf_DataIdB2" ) + ""; // not required
// 'java.lang.String' to javascript primitive 'string'

if( strTsv === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " TSV String {A} is empty \n" );
}
let numColsB = 0;
if( dataIdB !== "" ){
  numColsB  = engine.findDataDefinitionByNumber( dataIdB )
                    .getSubDataDefinitions().size() - 0;
  engine.log( " AutomatedTask TableConfig:" +
              " #of {B}-Columns Definition: " + numColsB );
}
let numColsB2 = 0;
if( dataIdB2 !== "" ){
  numColsB2  = engine.findDataDefinitionByNumber( dataIdB2 )
                     .getSubDataDefinitions().size() - 0;
  engine.log( " AutomatedTask TableConfig:" +
              " #of {B2}-Columns Definition: " + numColsB2 );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// (nothing)


//// == Calculating / 演算 ==
let twoDimArrayA = []; // for TSV-A
const arrTsv = strTsv.split("\n");
engine.log( " AutomatedTask MultilineString:" + 
            " TSV {A}, number of lines " + arrTsv.length );
for( let i = 0; i < arrTsv.length; i++ ){
  twoDimArrayA[i] = arrTsv[i].split("\t");
}

let outputTable1 = new com.questetra.bpms.core.model.formdata.ListArray();
if( dataIdB !== "" ){
  for( let i = 0; i < arrTsv.length; i++ ){
    let tmpRow = new com.questetra.bpms.core.model.formdata.ListArray.ListRow();
    if( twoDimArrayA[i].length < numColsB ){
      for( let j = 0; j < twoDimArrayA[i].length; j++ ){
        if( engine.findDataDefinitionByNumber( dataIdB )
                  .getSubDataDefinitions()
                  .get(j).matchDataType("DECIMAL") ){
          twoDimArrayA[i][j] = twoDimArrayA[i][j].replace( /,/g, "" );
        }
        tmpRow.addCol( twoDimArrayA[i][j] );
      }
      for( let j = 0; j < numColsB - twoDimArrayA[i].length; j++ ){
        tmpRow.addCol( "" ); // Fill with empty characters
      }
    }
    if( twoDimArrayA[i].length >= numColsB ){
      for( let j = 0; j < numColsB; j++ ){
        if( engine.findDataDefinitionByNumber( dataIdB )
                  .getSubDataDefinitions()
                  .get(j).matchDataType("DECIMAL") ){
          twoDimArrayA[i][j] = twoDimArrayA[i][j].replace( /,/g, "" );
        }
        tmpRow.addCol( twoDimArrayA[i][j] );
      }
    }
    outputTable1.addRow( tmpRow );
    engine.log( " AutomatedTask:" +
                " Add B[" + i + "]" );
  }
}

let outputTable2 = new com.questetra.bpms.core.model.formdata.ListArray();
let numOriginLines = 0;
if( dataIdB2 !== "" ){
  if( engine.findDataByNumber( dataIdB2 ) !== null ){
    outputTable2 = engine.findDataByNumber( dataIdB2 ); 
    numOriginLines = engine.findDataByNumber( dataIdB2 ).size() - 0;
  }
  engine.log( " AutomatedTask:" +
              " #of {B2}-Rows: " + numOriginLines );

  for( let i = 0; i < arrTsv.length; i++ ){
    let tmpRow = new com.questetra.bpms.core.model.formdata.ListArray.ListRow();
    if( twoDimArrayA[i].length < numColsB2 ){
      for( let j = 0; j < twoDimArrayA[i].length; j++ ){
        if( engine.findDataDefinitionByNumber( dataIdB2 )
                  .getSubDataDefinitions()
                  .get(j).matchDataType("DECIMAL") ){
          twoDimArrayA[i][j] = twoDimArrayA[i][j].replace( /,/g, "" );
        }
        tmpRow.addCol( twoDimArrayA[i][j] );
      }
      for( let j = 0; j < numColsB2 - twoDimArrayA[i].length; j++ ){
        tmpRow.addCol( "" ); // Fill with empty characters
      }
    }
    if( twoDimArrayA[i].length >= numColsB2 ){
      for( let j = 0; j < numColsB2; j++ ){
        if( engine.findDataDefinitionByNumber( dataIdB2 )
                  .getSubDataDefinitions()
                  .get(j).matchDataType("DECIMAL") ){
          twoDimArrayA[i][j] = twoDimArrayA[i][j].replace( /,/g, "" );
        }
        tmpRow.addCol( twoDimArrayA[i][j] );
      }
    }
    outputTable2.addRow( tmpRow );
    engine.log( " AutomatedTask:" +
                " Add B2[" + (numOriginLines + i) + "]" );
  }
}


//// == Data Updating / ワークフローデータへの代入 ==
if( dataIdB !== "" ){
  engine.setDataByNumber( dataIdB, outputTable1 );
}
if( dataIdB2 !== "" ){
  engine.setDataByNumber( dataIdB2, outputTable2 );
}

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

Download

Capture

TSV文字列をテーブル型データに変換します。TSV文字列内の全てのセルの文字列値がテーブル型データ項目Bに上書きコピーされます。テーブルのカラム設計に不整合がある場合、エラーとなる場合があります。

Notes

  1. 全てのセル値の文字情報をコピーします。
  2. カラムの表示順にコピーします。(カラムIDに依らない)
  3. カラム列数が少なくなる場合は、右列部がカットされます。
  4. カラム列数が増える場合は、空白文字列で補完されます。
  5. 数値カラムへの値コピーは、ピリオド “.” を小数点として認識して代入します。
  6. 数値カラムへの値コピーは、桁区切り文字 “,” が存在しても構いません。
  7. 選択カラムへの値コピーは、選択肢IDでなければなりません。(コピーされません)
  8. 自動計算カラムは、再評価されます。(必ずしも同じ値になりません)
  9. 既に格納されているセルデータを消さずに追記したい場合は、B2をご利用ください。

See also

コメントを残す

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

上部へスクロール

Questetra Supportをもっと見る

今すぐ購読し、続きを読んで、すべてのアーカイブにアクセスしましょう。

続きを読む